will_paginate
will_paginate copied to clipboard
paginate_by_sql and :order => "blabla DESC" doesn't work
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!
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.