Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a transient variable in a Grails Domain Class?

How do I set up a variable within a domain class that is not persistent. I want to be able to write and read to that variable, but I don't want it to be a part of the table.

The way to do this in rails is by setting up a variable with attr_accessor. Is this possible in Grails? Does anyone know how to do this?

Thanks!

like image 889
coderberry Avatar asked Dec 16 '11 15:12

coderberry


1 Answers

Just add the names of all the transient variables to the transients list, e.g.

class MyDomain {

  static transients = ['nonPersistent', 'nonPersistent2']

  Integer nonPersistent
  Integer nonPersistent2

  Integer persistent
  Integer persistent2      
}
like image 161
Dónal Avatar answered Oct 22 '22 12:10

Dónal