Forum: Ruby on Rails NameError when trying to combine Recipe 14 (rich HABTM) & Re

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.
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-03-12 22:56
(Received via mailing list)
Hi all,

I'm trying to model self-referential relations between people, where the
relation has attached data.
     John 'works for' Bob

Problem: ':through' doesn't work, and generates a NameError.

=> the models :
     Person    (attr: name)
     Relation  (attr: source_id, target_id)
       (more details below)

ex: John 'works for' Bob
1>   jsmith = Person.create(:name => 'John Smith')
2>   jdoe   = Person.create(:name => 'John Doe')
3>   jsmith.to_relations.create(:name => "works_for", :target => jdoe)
4>   assert_equal 1, jsmith.slaves.size
 >>>>
     NameError: activesupport/lib/active_support/dependencies.rb:106:in
`const_missing': uninitialized constant Slafe


Models
------------------------------------

   class Person < ActiveRecord::Base
       has_many    :to_relations  , :foreign_key => 'source_id',
:class_name => 'Relation'
       has_many    :slaves , :through => :to_relations   <<---- DOES NOT
WORK !!!!!!!
   end


   #  id                  :integer(11)   not null
   #  source_id           :integer(11)
   #  target_id           :integer(11)
   #  name                :string(255)
   class Relation < ActiveRecord::Base
       belongs_to  :target ,  :foreign_key => 'target_id', :class_name
=> 'Person'
   end


Any idea?

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