Unique subclass restrictions

I currently have a set of domain subclasses that display through a table behind the hierarchy. One of the attributes of the base class must be unique, but only in each subclass. My initial thought was to use the discriminator to create a unique constraint with multiple columns, something like this:

BaseClass {
   String name

   static constraints = {
       name unique 'discriminator'
   }
}

I am returning an error:

Scope for constraint [unique] of property [name] of class [class BaseClass] must be a valid property name of same class

Is there a way to use the discriminator for this purpose or another way to set a unique property for each subclass? Switching from table to subclass is not valid in the table.

+4
source share
1 answer

, . , , "".

SubClass extends BaseClass {
    static constraints = {
        name unique: 'class'
    }
}
+2

Source: https://habr.com/ru/post/1654866/


All Articles