Sign in through GitHub

Please read for an updated status on RailsCasts:

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