Greetings,
I have an application where Companies
and Users
need to belong to each other through a CompanyMembership
model, which c
I stumbled across this answer and believe that nowadays there is a nicer way using has_many association scopes
(has_many documentation):
has_many :admins, -> { where(admin: true) }, through: :company_memberships, class_name: :user
The second parameter of a has_many association can be a proc or lambda that contains your filter.