FWIW In a recent project managed to circumvent this problem by
querying and pre-fetching all child items before starting the outer
loop(s). (I hope there's a simpler way!)

As I recall it would mean your code would look something like this:
(untested)

# Coax DM into preloading collections:
customers = Customer.all(:limit => 3)
customers.orders.reload
customers.orders.order_lines.reload

#For items you may need to prepare something like:
item_ids = customers.orders.lines.map{|l| l.item_id }
items    = Item.all( :id => item_ids )

# Then try your original loops with a slight tweak for item.sku:
customers.each do |c|
  c.orders.each do |o|
    o.order_lines.each do |ol|
      a = "#{c.name}: #{o.reference} #{ol.quantity} x
#{ items.first(:id => ol.item_id).sku }"
    end
  end
end

Food for thought anyway. Hopefully a more DM-savvy reader can improve
on this.
George


On Sep 30, 8:24 am, Marcel Hild <[email protected]> wrote:
> Hi,
> I recreated the model found 
> athttp://datamapper.org/docs/find#nested_conditions
> When I want to print out all Customers with all Orders, including
> OrderLines and everything,
> Datamapper eager loads the first association (Customer.orders) but for
> the rest
> it will issue n queries.
>
> I created a gist which shows it athttp://gist.github.com/604156
>
> Is there a way to have more control of what is loaded or should I fire
> the query differently?
>
> thanks for any input
>
> marcel

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to