10/02/01 18:40:58
>>796
parentsテーブルがchild1とchild2のIDを持っているということは、やりたいことは
parent.children1 や parent.children2 (Parent has_many Child)
ではなく
parent.child1 や parent.child2
であってる?
class Parent < ActiveRecord::Base
belongs_to :child1, :class_name => 'Child', :foreign_key => 'child1'
belongs_to :child2, :class_name => 'Child', :foreign_key => 'child2'
end
class Child < ActiveRecord::Base
has_one :parent
end
でいいと思ったんだけど、これじゃchild1とchild2のどっちで結合すればいいか
特定できないからchild側からはparent参照できないのか。
(has_one parent1とかすれば可だけど)