user2498465
user2498465

Reputation: 77

Grails 2.4.3, isDirty flag not set on new domain object

I am not seeing the is dirty flag coming back as true.
To set this up create an empty project using grails 2.4.3 Within a controller save function past the following code:

def data = [firstName:'X', lastName:'Y']
Person p = new Person()
bindData(p, data)
println p.toString()
println p.dirtyPropertyNames
println p.isDirty()

Domain class:

class Person {
    String firstName
    String lastName
    static constraints = {
    }

    String toString(){
        return lastName + ': ' + firstName
    }
}

My results

p.toString() == Y: X 
p.dirtyPropertyNames == []
p.isDirty() == false

Anybody else getting the same issue? This seems to be an issue when creating a new domain object from the dataBind. Thus when I attempt to save the domain object, it is not going to save because the record is not dirty. In the version 2.2.2, this would be considered dirty and the documentation says it is dirty.

Upvotes: 0

Views: 728

Answers (1)

Dónal
Dónal

Reputation: 187529

A property is considered "dirty" if the value of the property has been changed (but not yet persisted) since it was loaded from the database. In your example, the Person instance has never been persisted, so none of the properties can be dirty

Upvotes: 2

Related Questions