更新时和删除时触发器
在两个表之间添加关系时,我可以选择向外部表的更新时和删除时事件添加触发器。现在我明白了,当外表被删除时,本地表中会触发On-Delete事件。
一个例子是一对一关系中的用户和配置文件。在 Propel 中,这提供了一些额外的功能,使查找附加记录比使用外键查询更简单。现在,我使用 CASCADE 的删除触发器将主键设置为用户表的外键。这意味着当我删除用户记录时,个人资料记录也会被删除。
现在,级联更新触发器会做什么?使用 propel 时,我可以更改配置文件属性而不保存,然后对用户调用保存,如果我为配置文件设置了级联更新,则在保存用户时会自动保存/更新配置文件信息 ?
之所以如此令人困惑,是因为这些表不了解 Propel,因此 On-Update 和 Propel 文档仅解释了 On-Delete 触发器的使用。
任何与 Propel 有关的见解都将不胜感激。一些通用定义不是我想要的。
When adding a relationship between two tables, I am offered the choice of adding triggers to the On-Update and On-Delete events of the foreign table. Now I understand that when the foreign table is deleted, the On-Delete event will be triggered in the local table.
An example of this is a user and profile in a one to one relationship. In Propel this offers some extra functions to make finding attached records simpler than querying using a foreign key. Now, I have the primary key set as a foreign key to the user table with an On-Delete trigger of CASCADE. This means that when I delete the user record, the profile record(s) gets removed as well.
Now, what would a cascading On-Update trigger do? When using propel I can change the profile properties without saving and then call save on the user, if I have cascading on-update set for profile, will it automatically save/update the profile information when saving a user?
The reason this is so confusing is because the tables don't know about Propel, so there must be another reason for the On-Update and the Propel documentation only explains the use of the On-Delete trigger.
Any kind of insight relating to Propel would be greatly appreciated. Some generic definition is not what I am looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非自 1.2 以来发生了变化,否则这些只是传统 RDBMS 约束的简单实现(本机或模拟)(mysql 5.5 约束文档)。这与推动无关,它与数据库有关。因此,
ON UPDATE
将允许您级联更新的键值 - 这假设您拥有可以更改值的 FK。与其他栏目没有任何关系。即使您没有打开 CASCADE,只要相关对象在您向其发出保存的对象上水合,它也会执行此操作。
ON UPDATE
内容与此无关,事实是两者之间存在关系,因此每个类中都有允许此操作的对象成员。当您对对象调用 save 时,它会遍历所有水合对象和集合,并保存标记为已更改的所有内容。Unless things have changed since 1.2 these are simply implementations (either native or emmulated) for tradidional RDBMS constraints (mysql 5.5 constraints docs). This has nothing to do with propel it has to do with databases. Thus
ON UPDATE
would allow you to CASCADE the updated key value - this assumes you have FK's where the value can change. It doesnt have anything to do with other columns.It will do this even if you dont have
CASCADE
turned on as long as the related object is hydrated on the object you issue the save to. TheON UPDATE
stuff has nothing to do with this, its the mere fact that the two carry a relationship and thus have object members in each class that allows for this. When you call save on an object, it goes through all hydrated objects and collections and saves anything that is marked as changed.