更新多条记录CF-ORM
在我的应用程序的几个数据结构中,我有一个名为“IsPrimary”的属性。我遇到的一个问题是,对于每个用户,他们只能有 1 个主要地址,但有多个地址。我想弄清楚的是,在 cf9 的 hibernate 实现中,如果在 IsPrimary 为 true 的情况下保存新记录或更新的记录,如何将属性 IsPrimary 为 true 的任何现有记录更新为 false。
这是我现有的保存方法
public UserAddress function save(required UserAddress)
{
var userAcc = entityLoadByPK('UserAccount', arguments.UserAddress.getUserID());
arguments.UserAddress.setUserID(userAcc);
entitySave(arguments.UserAddress);
return arguments.UserAddress;
}
In several data structures with my application I have an attribute named "IsPrimary". One issue I am having is that with for each User they can only have 1 primary address but have multiple address. What I am trying to figure out is with in cf9's implementation of hibernate how can I update any existing record that has the attribute IsPrimary as true to false if a new record or updated record is saved with IsPrimary being true.
This is my existing save method
public UserAddress function save(required UserAddress)
{
var userAcc = entityLoadByPK('UserAccount', arguments.UserAddress.getUserID());
arguments.UserAddress.setUserID(userAcc);
entitySave(arguments.UserAddress);
return arguments.UserAddress;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您愿意,可以在
preInsert()
处执行此操作。you may do it at
preInsert()
if you like.