I am loading about 100 students. There is a single query to get them
"select * from students...".

Then, it appears that it is doing an individual query for each
student, to find that students homeroom, then another for that
homeroom's classroom. It is not loading all of the classrooms in a
single query, nor the homerooms. So for the 100 students, it does one
query for student, 100 queries for homerooms, and 100 queries for
classrooms (though some appear to be cached).

I thought it should only do 3 queries.

Thanks
Tom

On Dec 3, 9:02 am, Frederick Cheung <[EMAIL PROTECTED]>
wrote:
> On Dec 3, 1:55 pm, hoenth <[EMAIL PROTECTED]> wrote:> Fred,
>
> > I appreciate your quick response.
>
> > I am confused though. I thought the point of includes was to get all
> > of the related objects in as few db calls as possible. From the log
> > file, it is making individual calls for each classroom and each
> > homeroom. So for every student, it finds that student's homeroom with
> > one call, then finds that homeroom's classroom with another call.
>
> When you're onlyloadingone then the joins based stuff doesn't make
> much sense.
> Were you to load 100 students the current code would load those
> students, then in query number 2 load all the homerooms and then the
> classrooms in the 3rd one.
>
> > I supposed it will eventually cache all of the classrooms, but since
> > homerooms is a join table, (one record for each student) it won't be
> > able to.
>
> > What about has_one :through in 2.1 is broken? I am running 2.1.2
>
> It was just screwed. Looks like it was backported to 2.1.2 though so
> you should be ok.
>
> Fred
>
> Fred
>
> > Thanks for your help.
> > Tom
>
> > On Dec 3, 8:23 am, Frederick Cheung <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Dec 2, 10:45 pm, hoenth <[EMAIL PROTECTED]> wrote:
>
> > > > Any idea why Rails seems to be ignoring the :include?
>
> > > It's not  - that's the way it does includes now, one select per
> > > association type (unless it has to fallback to the old joins based
> > > code because conditions/order reference the included tables). In
> > > addition :include of has_one through was broken in 2.1.
>
> > > Fred
>
> > > > Any help would be greatly appreciated.
>
> > > > Best,
> > > > Tom
--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
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