在 doSelect 中捕获 Propel 对象的初始副本
我正在使用 Propel 1.6,并且需要对特定数据库中的所有表进行版本控制。我有许多表,每个表都有一个在模式中定义的版本化表(因此表“role”有一个表“role_versionable”作为其版本控制对应项)。在“角色”中保存记录时,我想在保存之前将现有记录复制到 role_versionable 中。
这本身很简单:我已将整个模式的基类设置为自定义类(它扩展了 BaseObject),并且我生成的所有行模型类都扩展了该类。在我的自定义保存例程中,我正在执行新的选择,然后将其保存到版本控制表中。但是,我应该能够在所有行类中拦截 doSelect[One],但我不想为模型中的每个表生成子对象。
因此,我想知道是否有一种方法可以挂钩 postSelect 或在每次 doSelect 之后自动调用,以在选择对象后获取对象的初始状态?当我对行进行版本控制时,这将为我节省额外的选择。
(详细信息:我以自定义方式执行此操作,因为我需要向版本表添加额外的元数据,我不相信 archive_behaviour 支持。)
I am using Propel 1.6 and have a need to version all tables in a particular database. I have a number of tables, each having a versionable table defined in the schema (so table 'role' has a table 'role_versionable' as its versioning counterpart). When saving a record in 'role' I would like to copy the existing record to role_versionable before doing the save.
This is in itself trivial to do: I've set the baseClass for the whole schema to a custom class (which extends BaseObject) and all my generated row model classes extend this class. In my custom save routine I am doing a fresh select and then saving that to the versionable table. However I should be able to intercept doSelect[One] in all row classes, but I don't want to have to generate child objects for every table in the model.
I am therefore wondering if there is a way I can hook into a postSelect or get called automatically after every doSelect, to grab the initial state of the object after it is selected? This will then save me the extra select when I come to version the row.
(Detail: I am doing this in a custom way as I need to add extra metadata to the version table, which I don't believe the archive_behaviour supports.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK 在调用
doSelect
之前或之后无法使用钩子。你最好的机会是在你自己的类中重写这个方法并自己添加一个钩子。我可能会编写自己的 Peer 构建器来做到这一点。威廉
AFAIK there is no way to use a hook before or after a call to
doSelect
. Your best chance is to override this method in your own class and to add a hook by yourself. I'll probably write my own Peer builder to do that.William