2009-11-03 115 views
1

我想我可能在维斯塔尔版本中发现了一个错误(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)从刚装入标注身体字段包含RDiscount对象,它的文字就开始“就挂出 - \”装傻\“ - 在商店”(这是什么身体作为第9版)

但是,如果我从一个刚装入标注恢复到revert_to(8),检查标注的身体,revert_to(:last)revert_to(9),注释的身体,而在9版本将是错误的(它将与版本8中的注释的主体匹配)

任何想法?

回答

3

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

  1. 你取一个Annotation“一”与RDiscount ID x的。
  2. 您将“a”还原为先前版本,RDiscount id更改为y。
  3. 您致电a.body,导致导轨加载RDiscount对象与id y。
  4. 您将“a”还原为:lastRDiscount id会再次变为x。
  5. 您再次拨打a.body,但rails已经加载了RDiscount对象,并将返回此对象。
+0

良好的通话 - 你能想出一个解决方法吗? – 2009-11-23 17:50:18

+0

你可以这样称呼你的关联:a.body(true)。这会强制rails从db中获取关联。可能有其他方式使用vestal版本,但我想不出任何漂亮的momemnt。 – Calavera 2009-11-23 20:54:15

相关问题