:through example

I’m trying to use :through to ‘link’ to models, but the << assignment
does not appear to work as I have it. Any help would be great :slight_smile:

User model:

has_many :assignments
has_many :jobs, :through => :assignments

Jobs model:

has_many :assignments
has_many :users, :through => :assignments

Assignments:

belongs_to :job
belongs_to :user

This is what I am trying to do, but it does not work.

@user.jobs << @job

If I manually populate the assignments table with user and job id’s I
can do @jobs = @user.jobs etc.

kris wrote:

I’m trying to use :through to ‘link’ to models, but the << assignment
does not appear to work as I have it. Any help would be great :slight_smile:

It’s not you, it doesn’t work. :slight_smile:

http://blog.hasmanythrough.com/articles/2006/04/17/join-models-not-proxy-collections

Alan