table name xxxx specified more than once

41 views
Skip to first unread message

Peter

unread,
Dec 4, 2009, 5:13:18 AM12/4/09
to Searchlogic
Hi,

I actually ran into a problem with includes:

The model:
Company has_many :jobs
Job belongs_to Satus

The code that fails is:

jobs=Job.search(:order => 'ascend_by_status_name',:status_name =>
'approved').all(:conditions => 'companies.id = 5645',:include =>
[:company,:job_status])

I also tried it with named_scopes:
jobs=Job.of_company(5645).search(:order =>
'ascend_by_status_name',:status_name => 'approved').all(:include =>
[:company,:job_status])
and
jobs=Job.of_company(5645).with_includes(:company,:job_status).search
(:order => 'ascend_by_status_name',:status_name => 'approved').all

the error:
table name "status" specified more than once
the SQL statement does a left outer join AND an inner join on status

The "solution" is to pass a :joins => :status to all. If you leave out
any of the querry modifiers (of_company, :order, :status_name) it
works,too.


Is this a known issue? Any workarounds? Tips?

Thanks

Peter





Reply all
Reply to author
Forward
0 new messages