I have:
class Service < ActiveRecord::Base
has_and_belongs_to_many :staffs
and
class Staff < ActiveRecord::Base
has_and_belongs_to_many :services
With the intermediate table services_staffs with columns services_id and staffs_id
The following query succeeds:
Staff.find( :all, :conditions => "service_id = #{service_id}" )
But going the other direction fails:
Service.find( :all, :conditions => "staff_id = #{staff_id}" )
with
Service Load (0.3ms) SELECT "services".*, t0.staff_id as the_parent_record_id FROM "services" INNER JOIN "services_staffs" t0 ON "services".id = t0.service_id WHERE (t0.staff_id IN (12,13,14)) Service Load (0.0ms) SQLite3::SQLException: no such column: staff_id: SELECT * FROM "services" WHERE (staff_id = 13)
ActiveRecord::StatementInvalid (SQLite3::SQLException: no such column: staff_id: SELECT * FROM "services" WHERE (staff_id = 13) ):
Any idea why??