Reputation: 1513
I have a class User which has a validation rule like:
def readyUserCount = User.createCriteria().count({
eq('userStatus',UserStatus.Ready)
})
if(100 > readyUserCount){
return true
}
When validated, it will count existing rows in the DB. The issue is when I update a object, it will trigger validation, validation will trigger flush, flush will trigger validation, validation will trigger flush, and never break up. (If I'm inserting instead of updating this issue does not occur). Can anyone help me?
Upvotes: 1
Views: 362
Reputation: 13495
Try withNewSession()
:
def count = User.withNewSession{ User.countByUserStatus(UserStatus.Ready) }
Upvotes: 2