Has_many through


#1

I have a User model defined as following :
has_many :memberships, :class_name => ‘Member’, :include => [ :group ]
has_many :members, :dependent => :delete_all
has_many :groups, :through => :memberships

and a Group model
has_many :members, :include => :user
has_many :users, :through => :members

finally the Member model
belongs_to :user
belongs_to :hub

given a group @group , a user @user,and a member @member
how do create the association ?

thanks for your help

erwin


#2

On May 14, 1:43 pm, Kad K. removed_email_address@domain.invalid
wrote:
[…]

given a group @group , a user @user,and a member @member
how do create the association ?

@member.user = @user
@group.members << @member

thanks for your help

erwin

Best,

Marnen Laibow-Koser
removed_email_address@domain.invalid
http://www.marnen.org