Telling GORM not to persist a property

ⅰ亾dé卋堺 提交于 2019-12-06 19:27:04

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/3846489/telling-gorm-not-to-persist-a-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!