这是维斯塔版本中的错误还是我做错了什么
我想我可能发现了 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)
,则正文字段包含一个 RDiscount 对象,其文本以“Justhangout -- \”playing possum\” 开头 - 在store”(这是版本 9 的主体)
但是,如果我从新加载的注释恢复到 revert_to(8)
,请检查注释的主体 revert_to(:last)
和 revert_to(9)
,版本 9 中的注释主体将是错误的(它将与版本 8 中的注释主体匹配)
有什么想法吗?
I think I might have discovered a bug in Vestal Versions (http://github.com/laserlemon/vestal_versions) -- it seems like revert_to
's behavior depends on the reverts I've done in the past with the same object. Here's an example:
>> 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">
I.e., if I revert_to(9)
from a freshly loaded annotation the body field contains an RDiscount object whose text starts "Just hanging out -- \"playing possum\" -- at the store" (which is what the body was as of version 9)
However, if I revert to revert_to(8)
from a freshly loaded annotation, check the annotation's body, revert_to(:last)
, and revert_to(9)
, the annotation's body while in version 9 will be wrong (it will match the annotation's body from version 8)
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是lvestal_versions中的错误,而是rails在版本更改后没有重新加载您的关联。
假设您的
Annotation
保存了RDiscount
的 id,会发生以下情况:RDiscount
获取Annotation
“a” > x 的 ID。RDiscount
id 更改为 y。a.body
,导致rails加载id为y的RDiscount
对象。:last
,RDiscount
id 再次更改为 x。a.body
,但rails已经加载了RDiscount
对象,并将返回该对象。This is not a bug in vestal_versions, it's rails not reloading your association after a version change.
Assuming your
Annotation
holds the id to yourRDiscount
the following happens:Annotation
"a" with anRDiscount
id of x.RDiscount
id changes to y.a.body
, causing rails to load theRDiscount
object with the id y.:last
, theRDiscount
id changes to x again.a.body
again, but rails has already loaded theRDiscount
object and will return this object instead.