views:

109

answers:

1

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 ?

+1  A: 

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.

Scott Warren
Thanks ! My mistake was to not instantiate processingPriority !
Fabien Barbier