Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0 final
-
Fix Version/s: 2.0.1
-
Component/s: None
-
Labels:None
-
Patch Submitted:Yes
-
Flagged:Impediment
Description
I have a user class where I would like the user id to be unique for records marked as not deleted
As a simplification I have the rstriction uniqueness on date deleted (2 deleted records at the same time should also not have the same user id):
class User {
String userId
Date dateDeleted
static constraints =
{ userId blank: false, unique: 'dateDeleted' dateDeleted nullable: true }}
However, if I save a user with userId = "User1" and a not null date deleted value
Then validate a 2nd user with userId = "User1" and a null date deleted, the unique constrain kicks in.
The problem appears in to be in org.grails.datastore.gorm.validation.constraints.UniqueConstraint
line 69:
final existing = constraintOwningClass.createCriteria().get { eq constraintPropertyName, propertyValue for(prop in group) { eq prop, target[prop] } }
evaluates to:
final existing = User.createCriteria().get { eq 'userId', 'User1' eq 'dateDeleted', null }
Which is returning a row, even though the saved user has a not null dateDeleted. This is causing the uniqueness to fire
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits