我正在通过Company
表格链接User
和Association
模型:
class User < ActiveRecord::Base
has_many :associations
has_many :companies, :through => :associations
class Company < ActiveRecord::Base
has_many :associations
has_many :users, :through => :associations
在我的协会中,我有一个名为active
的布尔列:
create_table "associations", :id => false, :force => true do |t|
t.integer "company_id"
t.integer "user_id"
t.boolean "active"
在我的公司控制器中,我正在尝试获取一个公司阵列,其中包括用户已被激活或未被激活的事实。
我设法使用了一个范围,但这只是为了过滤公司是否有效,而不是关联:
@companiesactive = @user.companies.by_status(true)
希望获得类似的结果:
@companiesuseractive = @user.companies.where("association.active", true)
非常感谢任何帮助。