1

我想我可能在 Vestal 版本 ( http://github.com/laserlemon/vestal_versions ) 中发现了一个错误——它的行为似乎revert_to取决于我过去对同一个对象所做的还原。这是一个例子:

>> a = Annotation.find(1384)
=> #<Annotation id: 1384, body: "Just hanging out -- \"playing possum\" -- at the stor...", last_updated_by_id: 3, created_by_id: 3, song_id: 30, deleted_at: nil, created_at: "2009-09-06 01:56:55", updated_at: "2009-10-27 22:02:35", referent: "in the spot playing possum\nDebating my destination,...", vote_score: 0>
>> a.revert_to(9)
=> 9
>> a.body
=> #<RDiscount:0x21cf7bc @filter_styles=true, @smart=true, @fold_lines=nil, @filter_html=nil, @text="Just hanging out -- \"playing possum\" -- at the store, lacing up the new Nikes, trying to decide where to go for dinner">


>> a = Annotation.find(1384)
=> #<Annotation id: 1384, body: "Just hanging out -- \"playing possum\" -- at the stor...", last_updated_by_id: 3, created_by_id: 3, song_id: 30, deleted_at: nil, created_at: "2009-09-06 01:56:55", updated_at: "2009-10-27 22:02:35", referent: "in the spot playing possum\nDebating my destination,...", vote_score: 0>
>> a.revert_to(8)
=> 8
>> a.body
=> #<RDiscount:0x21b5a10 @filter_styles=true, @smart=true, @fold_lines=nil, @filter_html=nil, @text="I.e. just hanging out -- \"playing possum\" -- in the living room, lacing up the new Nikes, trying to decide where to go for dinner">
>> a.revert_to(:last)
=> 11
>> a.revert_to(9)
=> 9
>> a.body
=> #<RDiscount:0x21b5a10 @filter_styles=true, @smart=true, @fold_lines=nil, @filter_html=nil, @text="I.e. just hanging out -- \"playing possum\" -- in the living room, lacing up the new Nikes, trying to decide where to go for dinner">

即,如果我revert_to(9)从一个新加载的注释中,body 字段包含一个 RDiscount 对象,其文本以“Just hang out -- \"playing possum\" -- at the store”开头(这是第 9 版的正文)

revert_to(8)但是,如果我从新加载的注释恢复,请检查注释的正文,revert_to(:last)revert_to(9),注释的正文在版本 9 中将是错误的(它将与版本 8 中的注释正文匹配)

有什么想法吗?

4

1 回答 1

3

这不是 vestal_versions 中的错误,它是在版本更改后不会重新加载您的关联。假设您Annotation持有您的 id,RDiscount则会发生以下情况:

  1. 你获取一个id 为 x的Annotation“a” 。RDiscount
  2. 您将“a”恢复到以前的版本,RDiscountid 更改为 y。
  3. 你打电话a.body,导致rails加载RDiscountid为y的对象。
  4. 您将 "a" 恢复为:last,则RDiscountid 再次更改为 x。
  5. a.body再次调用,但 rails 已经加载了该RDiscount对象并将返回该对象。
于 2009-11-23T15:45:21.977 回答