将更改记录到数据库
我有大约 15 个或多或少复杂的模型。我想跟踪其中的变化。最简单的方法是什么?保存后/更新后触发器?
性能很重要,但如果有一种复杂度低但性能下降的方法,我会这样做。
顺便说一句:我不想使用存储过程。 (尽管我可能会这样做,如果有一种非常简单的方法的话......)
谢谢,菲利普
I have around 15 more or less complex models. Of those I would like to track the changes. What's the simplest way? After-save/-update triggers?
Performance is important but if there is a way with low complexity but decreasing performance, I'll do it.
By the way: I do not want to use stored procedures. (Though I might, if there is a really simple way to do so...)
Thanks, Philip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有 verstal_versions ,它似乎可以做你想做的事情。
它为您指定的所有模型添加版本控制。例如,请参见:
然后您可以像这样使用模型的版本:
There is verstal_versions, which seems to do what you want to do.
It adds versionning over all the models you specify. See, for example :
Then you can use your model's versions like this :
您可能还想查看 ActiveRecord 提供的开箱即用的脏对象。这使您能够在对象保存过程中对其进行处理,以便您可以将更改记录到单独的表中。
You might also want to look at Dirty objects provided by ActiveRecord out of the box. This gives you the ability to work with objects while they're in the process of being saved so that you can log the changes to a separate table.