我有:has_and_belongs_to_many查询工作在一个方向上,不提出其他
class Service < ActiveRecord::Base
has_and_belongs_to_many :staffs
和
class Staff < ActiveRecord::Base
has_and_belongs_to_many :services
随着中间表services_staffs与列services_id和staffs_id
以下查询成功:
Staff.find(:all, :conditions => "service_id = #{service_id}")
但去另一个方向失败:
Service.find(:all, :conditions => "staff_id = #{staff_id}")
与
服务的负载(0.3ms的)选择 “服务” *,t0.staff_id为the_parent_record_id FROM “服务” INNER JOIN “services_staffs” T0 ON “services”.id = t0.service_id WHERE(t0.staff_id IN(12,13,14))服务负载(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) ):
任何想法为什么?
谢谢!它仍然没有工作,虽然,非常小号TRANGE。 – 99miles 2010-07-02 18:46:49
arg,我的错......应该是'staffs.staff_id'不是'services.staff_id' – 2010-07-02 18:57:23
太棒了,明白了!再次感谢。在我的情况下,它实际上是“staffs.id =?”。 – 99miles 2010-07-02 19:25:51