On Thu, Jan 22, 2009 at 1:58 PM, Max Williams <
[email protected]> wrote:

>
> After a bit of experimentation i confirmed for myself that that is
> indeed the case :)
>
> thanks a lot Andrew, this is great.  I'd seen named scopes before but
> never really used them much and never realised their potential for
> managing includes.
>
> One thing i noticed which is interesting...lessons are joined to assets
> through a join table, 'elements'.
>
> if i use the with_assets scope for an association that goes through a
> join table, then rails does a further join to the assets table, like
> you'd expect with an include, so we have this situation:
>
> user JOIN user_usb_lessons JOIN lessons JOIN elements JOIN assets
>
> If, however, it's a simple association (such as user.lessons, which just
> uses Lesson's user_id field) then rails splits it off into three sql
> calls:  the first to load the lessons, the second to load the elements
> (join table records) and the third to load the assets.
>
> I guess that three seperate simple calls were seen as preferable to a
> single JOIN?
>
> Anyway, thanks again!
> max
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
Yes, on more complicated joins, where Rails thinks it will be better, it
does split the query into multiple queries.

-- 
Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to