Reputation: 35928
What are the guidelines to save the instance in grails?
I am doing something like this:
def colorInstance = Color.findOrSaveByName(colorname)
if (colorInstance.startsWith("R")) {
colorInstance.isRColor = true;
}
Should I be calling colorInstance.save()
in the if block or not? and why?
Upvotes: 1
Views: 78
Reputation: 685
in grails 2.3.4 colorInstance .save flush:true
in grails 2.2.2 colorInstance.save(flush:true)
Upvotes: 0
Reputation: 4636
You can save an instance explicitly (just as per your example) whenever your flow requires it.
Consider that at the end of a request cycle, when a GORM session is flushed, a dirty check operation is performed. Objects that are binded to the session are compared against their original values and if changes are detected, they are persisted
.
From http://www.redwindsw.com/blog/2014-01-15-moving-from-rails-to-grails-differences-and-similarities, read the paragraph about The Hibernate Session.
Upvotes: 1