2009-11-03 42 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

相關問題