Something like this will work (ActiveRecord):
Customer.find(:all, :include => {:orders => {:order_lines => :product}})
Pretty trivial, and loads all the needed records in a single query.
Pretty trivial, and loads all the needed records in a single query.
> This will load all comments with a single query. This reduces the total number of queries to 3. More generally the number of queries will be 1 plus the number of associations named (except if some of the associations are polymorphic belongs_to - see below).
Good call. Still, the difference between 1 and 3 queries is nothing compared to 3 and 100s (n+1 problem).
I wonder what AR can't turn that into a single query.