Forum: Ruby on Rails :through example

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
kris (Guest)
on 2006-04-18 14:29
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 :)

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.
Alan F. (Guest)
on 2006-04-18 17:11
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 :)


It's not you, it doesn't work. :-)

http://blog.hasmanythrough.com/articles/2006/04/17...


Alan
This topic is locked and can not be replied to.