这是Vestal版本中的错误还是我做错了什么

时间:2009-11-03 08:03:15

标签: ruby-on-rails vestal-versions

我想我可能已经发现了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 hanging out - \”播放负鼠\“ - 在商店”(这就是身体是版本9)

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

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

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

  1. 您提取的Annotation“a”RDiscount ID为x。
  2. 您将“a”还原为以前的版本,RDiscount ID更改为y。
  3. 您致电a.body,导致rails加载ID为y的RDiscount对象。
  4. 您将“a”还原为:lastRDiscount ID再次更改为x。
  5. 您再次致电a.body,但rails已经加载了RDiscount对象并将返回此对象。