简体   繁体   中英

gorm domain class shared property

I have 4 classes

class Process {
    String status

}

class Request {
    String status = "incomplete"

    belongsTo = [parent: Parent]
}

class Response {
    String status = "incomplete"

    static belongsTo = [parent: Parent]
}

class Confirmation {
   String status = "incomplete"

   static belongsTo = [parent: Parent]
}

Then the status of Request, Response or Confirmation will be updated.

How can I achieve to autoupdate Process.status with the status of the last updated of the other three classes ?

Is there a particular grails-way to accomplish that ?

Without all the details on how your domains are mapped - specifically what the relationship from Process to Request, Response and Confirmation - I'll assume that you have access to Process from the other domains.

With that assumption, you can use GORM Events to achieve an update to Process.status on an afterUpdate event in the other domains.

For example, in Request, Response and Confirmation, you can define something like:

def afterUpdate() {
  .. //get Process some how
  process.status = this.status
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM