Search code examples
grails

Is it possible to refresh a property in Grails?


In order to refresh a domain object i.e to re-read the data from database we do refresh().

def b = Book.get(1)
…
b.refresh()

I am wondering whether we can refresh a property of the domain.

Suppose i have bound params to Book object and suppose i want to unbind the author property from the book object then is it possible to achieve that?

Let's consider the Book is defined as

class Book {
   String title
   String author
   String category
}

Suppose I do bindData(bookInstance, params). This will bind to all properties. I want to unbind the author after bindData. Is this possible?


Solution

  • I solved this by using bookInstance.author = bookInstance.getPersistentValue('author').