def names = domain.dirtyPropertyNames
for (name in names) {
def originalValue = domain.getPersistentValue(name)
def newValue = domain."$name"
}
但是如果我与其他 Realm 的关系是1-1
我如何访问该其他域的dirtyPropertyNames
def dirtyProperties = domain?.otherDomain?.dirtyPropertyNames
for (name in dirtyProperties ) {
def originalValue = domain?.otherDomain?.getPersistentValue(name)
def newValue = domain?.otherDomain?."$name"
}
但是我越来越
没有这样的属性:class:otherDomain的dirtyPropertyNames
最佳答案
在针对Grails 2.2.4和2.3.0进行测试时,这似乎不是问题。
您如何量身定制1:1关系?
这是一个示例,希望对您有所帮助:
class Book {
String name
String isbn
static hasOne = [author: Author]
}
class Author {
String name
String email
Book book
}
//Save new data
def book = new Book(name: 'Programming Grails', isbn: '123')
book.author = new Author(name: "Burt", email: 'test', book: book)
book.save(flush: true)
//Sanity check
println Book.all
println Author.all
//Check dirty properties of association
def book = Book.get(1)
book.author.name = 'Graeme'
def dirtyProperties = book?.author?.dirtyPropertyNames
for (name in dirtyProperties ) {
println book?.author?.getPersistentValue(name) //Burt
println book?.author?."$name" //Graeme
}
虽然,在wrt Grails 2.3.0中,您可以像下面那样与上面保持持久的1-1关系:
def author = new Author(name: "Burt", email: 'test')
def book = new Book(author: author, name: 'PG', isbn: '123').save(flush: true)
关于grails - 为子对象添加域dirtyPropertyNames,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18794636/