Forum: Ruby on Rails RE: Ordering Results returned by has_many relationship.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Campano, David (Guest)
on 2006-05-03 19:02
(Received via mailing list)
Since Order.order_lines is really just an array, then you can use the
sort feature of an array like this:

sorted = Order.order_lines.sort {|x,y| y.quantity <=> x.quantity }

Then do


Hope this helps!
This topic is locked and can not be replied to.