I have two models Club and users. users are regular authenticated
users and some of them might create a club. A club can also have
members (essentially users) and there are attributes and models that
apply to member but not to users.
Here is what I have right now.
Club => belongs_to :user
User => has_many clubs (since a user can host multiple clubs).
Now how do I fit this member model into the picture, a club can have
many member, but since a club only has one user(the user who owns the
club), I can't really do a Club => has_many :users. do i need to
create a different model named ClubOwner for users who host clubs or
is there a better way to do this.
I have two models Club and users. users are regular authenticated
users and some of them might create a club. A club can also have
members (essentially users) and there are attributes and models that
apply to member but not to users.
Here is what I have right now.
Club => belongs_to :user
User => has_many clubs (since a user can host multiple clubs).
Now how do I fit this member model into the picture, a club can have
many member, but since a club only has one user(the user who owns the
club), I can't really do a Club => has_many :users. do i need to
create a different model named ClubOwner for users who host clubs or
is there a better way to do this.
You can use something like
Club has_many :members, :class_name => 'User', :foreign_key =>
'club_membership_id'
User belongs_to :club, :foreign_key => 'club_membership_id'
However that will only allow a user to be a member of one club, so
probably you need a membership joins table so that you can have a club
with many members and users in many clubs, each through the
memberships table. The rails guide on activeRecord associations will
help you.