Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paginate_by_sql and :order => "blabla DESC" doesn't work #84

Open
tupolev opened this issue Nov 2, 2010 · 1 comment
Open

paginate_by_sql and :order => "blabla DESC" doesn't work #84

tupolev opened this issue Nov 2, 2010 · 1 comment

Comments

@tupolev
Copy link

tupolev commented Nov 2, 2010

Trying to paginate an activerecord set of records from a table, using:

@newBookings = Booking.paginate_by_sql Booking._SQL_FOR_NEW, :page => pageNew, :order => 'create_date DESC'

and being Booking._SQL_FOR_NEW = ['select * from bookings where booking_statuses_id = ?',Booking._NEW_STATUS.to_i]

The pagination works OK, but the order clause seems to be ignored. Putting the order clause in the native SQL sentence and removing it from the pagination command, everything works OK.

So, long story short: When using find_by_sql and thus, a native sql query, the pagination ":order" clause is futile. To avoid it, one must put the ordering clause in the SQL query.

¿Is it a bug or is it my fault for something I've missed?

PS: Its just a quick question. If it's not a known issue, I will provide all version details. Thanks!

@victor-github
Copy link

It doesn't, indeed. I worked around the issue by included the ORDER BY in the sql query that I pass to find_by_sql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants