boardbloke opened a new issue, #14377:
URL: https://github.com/apache/grails-core/issues/14377
I have a class that have fields that participate in a nullable constraint
thus:
class ContentItem implements Serializable {
String code
String channel
String content
static constraints = {
code(nullable: false, unique: ['channel'])
channel(nullable: true, unique: ['code'])
content(nullable: false)
}
The idea is that I can have content, identified by a code, specified for a
unique combination of code and channel. Because the channel property is
nullable I can specify a row that contains a code and "null" for the channel to
provide generic content when a channel does not have a specific content match
in the database.
However, In Grails5 I cannot save two rows thus:
code | channel | content
'aCode' | 'aChannel' | 'someContent'
'aCode' | null | 'defaultContent'
The second row fails the unique test.
Looking at the code in UniqueConstraint.groovy it looks like the
detachedCriteria that is build to determine whether a record already exists
only adds an equality test for a property in the array specified in the unique
constraint in the constraints closure if the value of that property is not
null. But that means it cannot cope with nullable DB columns.
--
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]