Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telling GORM not to persist a property

Is there a way of telling GORM not to persist a property? I'm planning to define a confirm password property on my User class that I'll use for validation, but shouldn't be persisted.

like image 305
Martin Dow Avatar asked Oct 02 '10 16:10

Martin Dow


2 Answers

Using transient key word GORM can be directed not to persist specific property.

Following code snippets shows the use of transient proerties

class Book {
  static transients = [ "digitalCopy" ]

  static constraints = {
    releaseDate(nullable: true)
  }    

  String author
  String title
  Date releaseDate
  File digitalCopy
}

digitalCopy property included in transient declaration notifies GORM not to persist digitalCopy

like image 157
Rutesh Makhijani Avatar answered Sep 21 '22 23:09

Rutesh Makhijani


OK - just managed to answer my own question with some more searching. Should have been more patient. A static transients property "defines a list of property names that should not be persisted to the database. This is often useful if you have read-only getters that include logic."

http://grails.org/doc/latest/ref/Domain%20Classes/transients.html

like image 35
Martin Dow Avatar answered Sep 25 '22 23:09

Martin Dow