複数の外キーは一つのモデルを指します。
796 ワード
複数の外鍵は一つのモデルを指し、極端な例を比較する:
http://stackoverflow.com/questions/307581/rails-model-has-many-with-multiple-foreign-keysクラシックname=>'Person'、'Person'は文字列でなければなりません。記号ではなく、大きさの書き込みはモデルと同じ でなければなりません。 has_マンリーはforeign_を指定しなければなりません。key someone.father
someone.mother
someone.children_of_father
someone.children_of_Mother
http://stackoverflow.com/questions/307581/rails-model-has-many-with-multiple-foreign-keys
class Person < ActiveRecord::Base
belongs_to :father, :class_name => 'Person'
belongs_to :mother, :class_name => 'Person'
has_many :children_of_father, :class_name => 'Person', :foreign_key => 'father_id'
has_many :children_of_mother, :class_name => 'Person', :foreign_key => 'mother_id'
end
注:someone.mother
someone.children_of_father
someone.children_of_Mother