RailsCasts Pro episodes are now free!

Learn more or hide this

ehoffmann's Profile

GitHub User: ehoffmann

Comments by

Avatar

This worked for me:

ruby
class Order 
...
def self.open_orders
    joins(:events).where("order_events.id IN (SELECT MAX(id) FROM order_events GROUP BY order_id) AND state = 'open'")
end