I can define default value in domain by this way :

class ProcessingPriority {

    static constraints = {
    }

    String processingPriority = "medium"

    String toString()
    {
        return processingPriority
    } 
}

If I'm using this in another domain (using one-to-one), processingPriority is not define to "medium" but "null", ex :

class AnnotationForm {

  static belongsTo = ProcessingPriority
  static constraints = {processingPriority()}

  ProcessingPriority processingPriority
  ...
}

How can I set my class AnnotationForm to define : String processingPriority = "medium" ?

Is there a best way to define default values in relationship 1to1 ?

Accepted Answer

I am not sure if I understand what you are asking however.

try

class AnnotationForm {

  static belongsTo = ProcessingPriority
  static constraints = {processingPriority()}

  ProcessingPriority processingPriority = new ProcessingPriority();
  ...
}

This will create the child object with defaults. If it's still null there must be something changing the value.

Written by Scott Warren
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki