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?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Have the same problem... http://www.ruby-forum.com/topic/107123 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 06/05/2007, at 3:44 PM, will wrote:> 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 => :authorsDo 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 methodCan 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---