pri_dev
pri_dev

Reputation: 11645

getting domain class property value by its String name

May be a basic question.. I am doing

MyDomain.dirtyPropertyNames.each {
aInstance.oldVal = newDomainObject.getPersistentValue(it)
aInstance.newVal = ? // how to get the property value here from the list obviously MyDomain.it doesnt work..
aInstance.save()
}

The dirtyPropertyNames is a list of Property name Strings, how do I get the Domain.property of each property in the list?

Thanks

Upvotes: 0

Views: 3898

Answers (2)

Big Ed
Big Ed

Reputation: 1244

I prefer the following form for property access through a name.

myDomain[it]

For instance, if your property name is "lockedFlag" the following are true.

assert myDomain.lockedFlag == myDomain["lockedFlag"]
assert myDomain.lockedFlag == myDomain."lockedFlag"

I hope this helps.

Upvotes: 2

tim_yates
tim_yates

Reputation: 171064

Does

myDomain."$it"

Do what you want?

Upvotes: 4

Related Questions