I spent all night working on this, then it dawned on me
I need to add a class_name to my HABTM definition
On Sep 2, 1:35 am, Dave Roberts <dave.a.robe... gmail.com> wrote:
> This one's driving me batty:
> I have a Publisher model and an Article model
> I want two HABTM relationships between Publishers and
Articles:
> authored_articles and edited articles.
> In my Publisher model:
>
> has_and_belongs_to_many :authored_articles,
:join_table=>'articles_authors'
>
> has_and_belongs_to_many :edited_articles,
:join_table=>'articles_editors'
> The join tables are both structured the same way, with
a publisher_id
> and an article_id
>
> p = Publisher.find_first
> p.authored_articles
> NameError: uninitialized constant
Publisher::AuthoredArticle
> from
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/
> active_support/dependencies.rb:477:in `const_missing'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
> active_record/base.rb:1360:in `compute_type'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
> active_record/reflection.rb:125:in `send'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
> active_record/reflection.rb:125:in `klass'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
>
active_record/associations/has_and_belongs_to_many_associati
on.rb:
> 158:i
> n `construct_sql'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
>
active_record/associations/has_and_belongs_to_many_associati
on.rb:6:in
> `initialize'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
> active_record/associations.rb:934:in `new'
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
> active_record/associations.rb:934:in
`authored_articles'
> from (irb):8>> p.asdf
>
> NoMethodError: undefined method `asdf' for
#<Publisher:0x4789124>
> from
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
> active_record/base.rb:1860:in `method_missing'
> from (irb):9
>
> Any suggestions would be helpful, thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrails googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribe googlegroups.com
For more options, visit this group at http://gro
ups.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---
|