【发布时间】:2014-09-16 13:47:08
【问题描述】:
我在 grails 项目中使用 GORM API 反映的 afterUpdate 方法。
class Transaction{
Person receiver;
Person sender;
}
我想知道修改哪个字段以使 afterUpdate 有相应的行为:
class Transaction{
//...............
def afterUpdate(){
if(/*Receiver is changed*/){
new TransactionHistory(proKey:'receiver',propName:this.receiver).save();
}
else
{
new TransactionHistory(proKey:'sender',propName:this.sender).save();
}
}
}
我可以使用beforeUpdate: 并在更新之前在全局变量(之前为Transaction)中赶上对象,然后在afterUpdate 中,将previous 与当前对象进行比较。
可以吗?
【问题讨论】:
标签: grails grails-orm aop