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
On 2/9/07, Florencio Cano
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> 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.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---