A bit weird relationship, how to relate this?

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.

Well I do see you’re missing a :through clause on Group:

class Group < ActiveRecord::Base
has_many :invitations
has_many :users, :through => :memberships
end

As for the @user.invitations, hmm…

class User < ActiveRecord::Base
has_many :memberships
has_many :groups, :through => :memberships
has_many :invitations, :through => :groups (?)
end

You might be better off defining a method User#invitations and building
the
relationship programatically.

Jason