:through difficulties


#1

I’m trying to use :through on a many-to-many relationship.

I’ve got the following three models:

class User < ActiveRecord::Base
has_many :authors
has_many :submissions, :through => :authors

class Author < ActiveRecord::Base
belongs_to :submission
belongs_to :user

class Submission < ActiveRecord::Base
has_many :authors
has_many :users, :through => :authors

I’ve also got test data for each of the models, but when I try to run
either of the following in script/console I get the subsequent error:

user.submissions
submission.users

NameError: undefined local variable or method

Any suggestions on how to figure out what I’ve done wrong?


#2

Have the same problem…

http://www.ruby-forum.com/topic/107123


#3

On 06/05/2007, at 3:44 PM, will wrote:

belongs_to :user

class Submission < ActiveRecord::Base
has_many :authors
has_many :users, :through => :authors

Do you have all the correct fields on these tables to support the
relationships?

I’ve also got test data for each of the models, but when I try to run
either of the following in script/console I get the subsequent error:

user.submissions
submission.users

NameError: undefined local variable or method

Can you post an exact log of what you’re typing in the console? I
suspect you’re just misusing the relationships somehow.

Cheers,

Pete Y.
http://notahat.com/