Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Fix for http://jira.grails.org/browse/GRAILS-8656 #23

Merged
merged 2 commits into from Feb 10, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -65,12 +65,34 @@ class UniqueConstraint extends AbstractConstraint{
}



final existing = constraintOwningClass.createCriteria().get {
eq constraintPropertyName, propertyValue
for(prop in group) {
eq prop, target[prop]
}
List nullConstraintParameters = group.findAll{target[it] == null}
def existing = false

if (nullConstraintParameters) {
existing = constraintOwningClass.createCriteria().list {
eq constraintPropertyName, propertyValue
for(prop in group) {
if (target[prop] != null) {
eq prop, target[prop]
}

}
}

// see if there is a result where all the nullConstraintParameters are null
existing = existing?.find {
null == nullConstraintParameters.findResult {param -> it[param]}
}

} else {
existing = constraintOwningClass.createCriteria().get {
eq constraintPropertyName, propertyValue
for(prop in group) {
if (target[prop] != null) {
eq prop, target[prop]
}
}
}
}

if(existing) {
Expand Down