Rails 3.0.x - 为什么其他模型正在更新?
我试图弄清楚别人编写的代码中的内容。有两个模型,具有简单的 has_many 关系(A->B)。
现在的问题是,在保存“B”模型的同时,“A”模型也在数据库中更新。现在,没有任何类型的回调,没有特殊的关系条件(:自动保存等),并且代码中也没有观察者。
问题是,定义这种行为的其他因素是什么?
更新:我正在尝试调试保存过程以跟踪任何内容,但是对内部 active_record 方法的大量调用让我不知所措,所以这个方法变得毫无用处。
额外问题:我如何转储当前模型回调(以防万一,它们以某种方式添加到我的 grep 技能中)。
I am trying to figure out things in code written by someone else. There are two models, with simple has_many relation (A->B).
Now the problem is, that while saving the "B" model, also the "A" model is updated in the database. Now, there is no callbacks of any sort, there is no special relation conditions (:autosave, etc), and also there is no Observers in the code.
The question is, what could be other things, which define this kind of behaviour?
Update: I am trying to debug the save process to track anything, but I am getting overwhelmend by the ammount of calls to internal active_record methods, so this approchach is getting useless.
Bonus question: How can I dump current model callbacks (in case, they were added in some manner which resistant to my grepping skills).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它可以有 :touch =>真的。该自动更新关联。
It could have :touch => true. That auto updates the association.
事实证明,这是一个非常复杂的内部应用程序错误。在结果中,从缓存中获取的记录被标记为未持久化,这迫使 ActiveRecord 在保存相关对象时创建重复记录。
This turned out to be very complicated, internal application bug with Marshaling. In the result records fetched from cache were marked as not persisted, which forced ActiveRecord to create duplicate record while saving related objects.