以rails 文档为例:
class Dungeon < ActiveRecord::Base
has_many :traps, :inverse_of => :dungeon
has_one :evil_wizard, :inverse_of => :dungeon
end
class Trap < ActiveRecord::Base
belongs_to :dungeon, :inverse_of => :traps
end
class EvilWizard < ActiveRecord::Base
belongs_to :dungeon, :inverse_of => :evil_wizard
end
Dungeon.create!.traps.create!
d = Dungeon.first
t = d.traps.first
d.level == t.dungeon.level # => true
d.level = 10
以下表达式返回 false,尽管它预期返回 true(至少对于 Rails 3.1):
d.level == t.dungeon.level # => false
有什么问题:inverse_of
?