I figured out my problem for one of the cases...
I had:
class Blog
has n, :posts
def latest_post
posts.first(:order=>[:created_at.desc])
end
end
And when I'd do
Blog.all.each{|b| b.latest_post.something}
It would generate a query for N posts for EACH blog, basically eager-
loading the same ones every time!
THE TRICK IS TO DO:
has 1, :latest_post, :class_name => Post, :order =>
[:created_at.desc]
And then it does just two queries, very nice.
-Gary
On Jan 14, 2:29 am, Michael Klishin <[email protected]>
wrote:
> On 14.01.2009, at 9:44, Gary Yngve wrote:
>
> > there are cases in which it seems that i am eager loading too much
> > and unnecessarily redundantly (potentially a bug of its own),
> > especially since i have to turn lazy off to guard against some other
> > bugs...
>
> There is no way to turn SEL on or off at this point. Can you give an
> example of when SEL misbehaves?
>
> MK
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---