I'm having an issue in using group by and order by in one statement in Rails 3
In my controller:
def index
@units = Unit.list_order.grouped
end
and my model:
scope :list_order, order("units.interior_code, units.created_at ASC")
scope :grouped, group("units.unit_parent")
The query is pulling back the data grouped (Unique records are displayed based on unit_parent) and is ordered by interior_code but it's not ordering the grouped records by date, i.e. there may be 4 grouped records and the query does not respect the date ordering to pull only the last record from the group
I've seen this post on SO which is a similar issue
Any help would be appreciated