これは通常のRailsの動作であり、基本的なものが欠けていると確信していますが、それは何ですか?
子供は親に属し、親には多くのメンバーがいます。
parent = Parent.create(:name=>"Kerkhoff, J")
child = parent.children.create(:first_name => "Sally")
puts child.parent.name # ==> Kerkhoff, J
parent.update_attributes(:name=>'Zorro, A')
puts parent.name # ==> 'Zorro, A'
puts child.parent.name # ==> 'Kerkhoff, J'
child.save # ==> true (Does saving the child refresh its parent.name?)
puts child.parent.name # ==> 'Kerkhoff, J' (No)
child = Child.find(child.id) # reload child from database
puts child.parent.name # ==> 'Zorro, A' (This does refresh the name)
のname
属性はparent
変更されておりchild
、同じ親を引き続き参照していますが、親の更新された属性は反映されていません。update_attributes
失敗の問題でもありません。Sallyのレコード(child
)がデータベースから再度取得されると、属性はの新しい値name
を反映します。parent
ここで何が起こっているのですか?
あなたの洞察に感謝します!