You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: