【发布时间】:2010-07-02 18:16:04
【问题描述】:
我有:
class Service < ActiveRecord::Base
has_and_belongs_to_many :staffs
和
class Staff < ActiveRecord::Base
has_and_belongs_to_many :services
使用带有列 services_id 和 staffs_id 的中间表 services_staffs
以下查询成功:
Staff.find( :all, :conditions => "service_id = #{service_id}" )
但是换个方向失败了:
Service.find( :all, :conditions => "staff_id = #{staff_id}" )
与
服务负载 (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)) 服务负载 (0.0ms) SQLite3::SQLException: 没有这样的列:staff_id: SELECT * FROM "services" WHERE (staff_id = 13)
ActiveRecord::StatementInvalid(SQLite3::SQLException:没有这样的列:staff_id: SELECT * FROM "services" WHERE (staff_id = 13)):
知道为什么吗??
【问题讨论】:
标签: ruby-on-rails has-and-belongs-to-many