Hi!
I’m new to ROR and I have a problem creating a relationship. I don’t
know how to do this neatly.
I have:
class User < ActiveRecord::Base
has_many :memberships
has_many :groups, :through => :memberships
end
class Invitation < ActiveRecord::Base
belongs_to :group
belongs_to :event
end
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :group
end
class Group < ActiveRecord::Base
has_many :invitations
has_many :memberships
end
The groups have invitations to events through invitations. The users are
members of groups through memberships. I want to create the relation
@users.invitations where I will have all the invitations to the groups
that the user is member.