tags:

views:

27

answers:

1

it is very common to use domainClass.properties = params to bind all incoming request params to a domain class object. i do not understand why this assignment automatically updates the domain object. e.g.

def update = {
  def book = Book.get(1)
  book.properties = params
  book.discard()
}

the params assignment updates the domain object. discard method has no effect. can anyone help me?

+1  A: 

The discard() method will not reset the book instance, only prevent that it will be saved automatically by Grails. To reset the book instance you need to reload it, e.g. using Book.get(1).

And book.properties = params will simply try to assign the elements in the params map to properties of Book where the property name is the same as the map entry key. I believe this is standard Groovy functionality, and not Grails specific.

Ruben
thanks for the answer. my problem is that through data binding the obj get persisted when some properties of the domain obj. has been changed. see my comment before.
hitty5