I have two models: Person and Relation. The second one stores information about relations between two people. It has parent_id and child_id fields and doesn`t have id field. I connected it with has_many :through and it works.
But:
- Relation.find(:all) returns empty array even if there are some relations in the table (becouse there is no id field).
- I don`t know how to delete relation.
My models looks like this:
class Person < ActiveRecord::Base
has_many :child_relations,
:class_name => "Relation",
:foreign_key => "parent_id"
has_many :parent_relations,
:class_name => "Relation",
:foreign_key => "child_id"
has_many :children, :through => :child_relations
has_many :parents, :through => :parent_relations
end
class Relation < ActiveRecord::Base
belongs_to :parent, :class_name => "Person"
belongs_to :child, :class_name => "Person"
end
Any suggestions?
UPDATE: I've used has_many :through becouse I also store information about a type of the relation in the table. Currently I gave up and I added id field to my table (Rails convention...). But my question remains open.