RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: ehoffmann
This worked for me:
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
This worked for me: