2016-04-07 8 views
0

Ich habe 2 ModelleRuby on Rails Abfrage im Zusammenhang

FALTBLÄTTER : name : PARENT_ID

AUTHFOLDERS : FOLDER_ID : company_id : user_id : Rolle #for teilen

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 

Wie kann man "Ordner" wählen, wo Authfolders.company_id = x?

Antwort

0

Sie mit Ihrem verknüpften Tabelle beitreten können und stellen Sie dann Ihre Bedingung:

Folder.joins(:authfolders).where('authfolders.company_id = :company_id', company_id: x)