rails ActiveRecord join tables cascading belongs_to -
given following simple associations, , selected_company, query correctly written documents in selected company ?
class document < activerecord::base belongs_to :user end class user < activerecord::base belongs_to :company has_many :documents end class company < activerecord::base has_many :users end === query selected_company: company.first documents_in_selected_company = document.joins(:user).joins(:user => :company).where(:company_id => selected_company[:id)
thanks feedback
just 2 small fixes , association names should lowercase ... , should contains query string :
documents_in_selected_company = document.joins(:user).joins(:user => :company).where("companies.id = ?", company.id)
Comments
Post a Comment