#512 ✓resolved
Ewout

Strategic eager loading and asking children.first

Reported by Ewout | August 4th, 2008 @ 07:45 AM

On lines 112-114 in relationship.rb, the collections with loaded child elements are prepared for all parents the strategic eager loading applies to.

These collections are initialized lazily, with a block.

Consequence: the collection does not mark itself as loaded and when asking parent.children.first, a query will be executed instead of just looking the first child up in the loaded array of children.

I suppose this is not the desired behaviour. Fix is to initialize the collection immediately and mark it as loaded.

So instead of:

parents_children = Collection.new(query) do |collection|

children.each { |child| collection.send(:add, child) }

end

parents_children = Collection.new(query)

children.each { |child| parents_children.send(:add, child) }

parents_children.send(:mark_loaded)

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages