homicki commented on issue #14503:
URL: https://github.com/apache/grails-core/issues/14503#issuecomment-6092234375
This is still present on 8.0.0 with grails-data-hibernate7 (MariaDB 10.11
and MySQL 8.4). When a group value is null, `UniqueConstraint.processValidate`
leaves that property out of the query, so the row is checked against every
group. That is stricter than both fixes discussed above, and stricter than the
database's unique index.
Neither fix alone fits every domain:
```groovy
class Folder {
String name
Folder parent
static constraints = {
name unique: 'parent'
parent nullable: true
}
}
class Translation {
String code
Locale locale // null = default text
String text
static constraints = {
code unique: ['locale']
locale nullable: true
}
}
```
- `Folder`: a top-level `Archive` fails when any folder named `Archive`
exists at any level. When top-level folders belong to different owners, only
"skip when null" is right.
- `Translation`: a default row fails when any locale has the code. Here
"is null" is right: it still rejects a second default row for the same code,
which a MySQL or MariaDB unique index would not.
**Proposal:** keep SQL semantics as the default (a null group value skips
the check), and add an opt-in that matches nulls with `isNull`:
```groovy
code unique: [group: ['locale'], nulls: 'match']
```
This also covers the request in #14656. We'd be happy to submit a PR if
this direction works, since we currently replace these constraints with
per-domain validators.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]