Harold
 to me

As far as I know, the reason for :include is mainly for eager loading.
If you know you will be querying the sections table for the companies
you are finding, doing an :include will retrieve those sections in one
query, ie, one trip to the DB. If you don't pass in the :include
option to the initial find, doing the_company.all-sections would go to
the database to retrieve the associated records and then build the
section object.

I usually use :joins when I want to narrow down the search even
further, for instance, to companies who have sections, persons who
also have users, etc.

For example:
Company.find(:all, :include => :all-sections, :conditions => '...')
Would fetch all companies meeting those conditions, along with the
associated "all-section"s. Therefore it doesn't make sense to force it
to :select any specific columns, especially not columns on only one of
the tables - it defeats the purpose of the :include.

On the other hand:
Company.find(:all, :joins => :all-sections, :conditions =>
'..', :select => 'company.*')
works fine, however, :select => 'company.*' is redundant, and if you
will need the returned companies' sections, you will make a trip to
the DB that may have been avoided by using :include.



On Nov 18, 6:41 pm, boblu <[EMAIL PROTECTED]> wrote:
> yes, the compannies table does not have a columns called
> ref_company_id.
> It is the table which is referreced by the sections table that has a
> ref_company_id as a foreign key.
> Can you explain why that error comes out? 'cause I cannot find any
> clue about it.
>
> And thank you for mentioning your blog post, and I now know why I feel
> my app is much faster using join than  using include.
> Thank you.
>
> On Nov 18, 7:37 pm, Frederick Cheung <[EMAIL PROTECTED]>
> wrote:
>
> > Well to answer the question in the subject line, I wrote this a little
> > while 
> > back:http://www.spacevatican.org/2008/6/22/the-difference-between-include-...
> > A key thing to note is that include in 2.1 and include in 2.0.2 are
> > different (but the 2.1 code will fall back to the 2.0.2 code if
> > necessary).
> > Does the companies table not have columns called ref_company_id ?
>
> > Fred
--~--~---------~--~----~------------~-------~--~----~
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