2016-04-07 5 views
0

私は2モデルRubyのレール上のクエリに関連する

FOLDERS を持っている: に名前を付ける:

AUTHFOLDERS をPARENT_ID: をfolder_id: をのcompany_id:

class Folder < ActiveRecord::Base 
    has_many :authfolders 
    has_many :companies, :through => :authfolders 

    accepts_nested_attributes_for :authfolders 

    validates :name, presence: true 
end 

class Authfolder < ActiveRecord::Base 
    belongs_to :company 
    belongs_to :folder 
end 

を共有#for役割: をUSER_IDどうすれば "フォルダ"を選択できますか?​​?

答えて

0

あなたの関連テーブルと結合して、あなたの条件を設定することができます

Folder.joins(:authfolders).where('authfolders.company_id = :company_id', company_id: x) 
関連する問題