Filtering child objects in a has_many :through relationship in Rails 3

前端 未结 5 786
一个人的身影
一个人的身影 2021-02-01 19:23

Greetings,

I have an application where Companies and Users need to belong to each other through a CompanyMembership model, which c

5条回答
  •  失恋的感觉
    2021-02-01 20:19

    An even cleaner way would be to add an association to your Company model, something like this:

    has_many :admins, :through => :company_memberships, :class_name => :user, :conditions => {:admin => true}
    

    You might have to dig into the rails doc to get the exact syntax right.

    You shouldn't need :include, unless you have other classes associated with :user that you might reference in your view.

提交回复
热议问题