Forum: Ruby on Rails :through difficulties

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.
C3d4a58e17c7b7680231c2df39aa2d99?d=identicon&s=25 will (Guest)
on 2007-05-06 07:46
(Received via mailing list)
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?
E3513c4edd6810bb4b9914b58da2a2c3?d=identicon&s=25 Jamal Soueidan (jamal)
on 2007-05-06 12:36
Have the same problem...

http://www.ruby-forum.com/topic/107123
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2007-05-08 03:09
(Received via mailing list)
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 Yandell
http://notahat.com/
This topic is locked and can not be replied to.