我觉得http://guides.rubyonrails.org/association_basics.html#self-joins上给出的以下自加入模型示例不正确。
class Employee < ActiveRecord::Base
has_many :subordinates, :class_name => "Employee",
:foreign_key => "manager_id"
belongs_to :manager, :class_name => "Employee"
end
我觉得应该如下。你能建议哪一个是正确的,为什么?
class Employee < ActiveRecord::Base
has_many :subordinates, :class_name => "Employee",
belongs_to :manager, :class_name => "Employee", :foreign_key => "manager_id"
end
我的理由:模型轴承belongs_to
关系带有它引用的模型的foreign_key。