我有一个Grails领域,看起来像下面Grails领域瞬态和计算
User {
sortedSet notifications
static hasMany=[notifications:Notification]
}
Notification {
Date dateCreated
int status=0
static belongsTo=[user:User]
@Override
public int compareTo(obj) {
dateCreated.compareTo(obj.dateCreated)
}
}
如果我返回“用户”对象的GSP,有没有办法让所有的通知,其中状态的计数= 1。
例如:user.notifications.size()(但是其中状态= 1)
而不必返回另一个单独的通知对象。
嗨,谢谢,这是最好的解决方案! – 2014-09-02 10:11:18