I have a User model, a Membership model, and a Club model. I have set up the following associations:
has_many :memberships has_many :members, through: :memberships
belongs_to :user belongs_to :club
What I want now is to have a has_one :organizer on Club that retrieves a single User record based on the member with the organizer attribute set to true in the join model.
How do I set up this has_one association? I've tried going through the memberships association, but an exception is raised that the memberships is a collection and needs to be singular.
I think I just figured it out...but in case someone else needs to know..
has_one :membership, conditions: ['memberships.organizer = ?', true] has_one :organizer, through: :membership, source: :user