开发者

How to keep default value in domain with Gorm relationship one-to-one?

开发者 https://www.devze.com 2022-12-26 05:25 出处:网络
I can define default value in domain by this way : class ProcessingPriority { static constraints = { } String processingPriority = \"medium\"

I can define default value in domain by this way :

class ProcessingPriority {

    static constraints = {
    }

    String processingPriority = "medium"

    String toString()
    {
        retur开发者_JS百科n 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 ?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消