On Mar 18, 12:01 am, David Lee <[email protected]> wrote: > When you do: > > Item.eager_graph(:user).all.first.type > > you get the type Item. However, when you do: > > Item.eager_graph(:user).each {|x| puts x.type} > > x will be a Hash. I expect each to pass Item objects instead of Hashes > to the block.
That's expected. In order to eager_graph to work, you need to call all on it (eager is the same). This is hinted at in the eager loading documentation, but it's not mentioned explicitly in the eager_graph method RDoc. I'll add a patch now. You must have all records before you can eager load via either eager or eager_graph. For eager, it's because you need to know the key fields for all objects. For eager_graph, it's because you need to build associations after all rows are available. each always yields a row at a time, so you would get many of the same objects (at least if you were using a to_many association), with each object having just the associated object for the currently returned row. Jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sequel-talk" 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/sequel-talk?hl=en -~----------~----~----~----~------~----~------~--~---
