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 S.’)
2> jdoe = Person.create(:name => ‘John D.’)
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