テーブルを介してモデル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)
どんな助けでも大歓迎です。