Sorry, that was my typo.
The correct error was:
###### table 1: companies ##########
id int
name string
###### table 2: sections ##########
id int
ref_company_id int
ref_meta_id int
sec_name string
class Company < ActiveRecord
has_one :main_section, :class=>"Section", :foreign_key=>"ref_company_id",
:conditions=>"ref_meta_id=0"
has_many :all_sections, :class=>"Section", :foreign_key=>"ref_company_id"
end
class Section < ActiveRecord
belongs_to :company, :class=>"Company", :foreign_key=>"ref_company_id"
end
Company.find(:all, :select=>'companies.*', :include=>
[:all_sections], :conditions=>"sections.sec_name='abc'")
*********************************************************************
Unknown column 'companies.ref_company_id' in 'field list':
SELECT `companies`.`id` AS t0_r0,
`companies`.`name` AS t0_r1,
`companies`.`ref_company_id` AS t0_r2,
`companies`.`ref_meta_id` AS t0_r3,
`companies`.`sec_name` AS t0_r4,
`sections`.`id` AS t1_r0,
`sections`.`ref_company_id` AS t1_r1,
`sections`.`ref_meta_id` AS t1_r2,
`sections`.`sec_name` AS t1_r3,
FROM `companies` LEFT OUTER JOIN `sections` ON
sections.ref_meta_id = companies.id
WHERE ( sections.sec_name='abc' )
**********************************************************************
the werid part is
`companies`.`ref_company_id` AS t0_r2,
`companies`.`ref_meta_id` AS t0_r3,
`companies`.`sec_name` AS t0_r4,
For now, though I am using :join and :group to get what I want.
I still got no idea where these errors came from when using :include.
On Nov 19, 4:28 pm, Frederick Cheung <[EMAIL PROTECTED]>
wrote:
> On 18 Nov 2008, at 23:41,bobluwrote:
>
>
>
> > 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.
>
> It's very weird - in particular it's weird that it goes t0_r0, t0_r16:
> the number after the r is generated by an each_with_index loop - it
> should skip over the numbers 1-15.
> Weird stuff might happen if you had overwritten the column_names or
> columns methods on your ActiveRecord class but I would have expected
> that to cause problems elsewhere too.
>
> Fred
>
>
>
> > 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
-~----------~----~----~----~------~----~------~--~---