2013-09-13 10 views
0
def names = domain.dirtyPropertyNames 
    for (name in names) { 
     def originalValue = domain.getPersistentValue(name) 
     def newValue = domain."$name" 
    } 

Но если у меня есть отношение 1-1 с другим доменомGrails dirtyPropertyNames домена для дочернего объекта

, как я могу получить доступ к dirtyPropertyNames для этого другого домена

def dirtyProperties = domain?.otherDomain?.dirtyPropertyNames 
    for (name in dirtyProperties) { 
     def originalValue = domain?.otherDomain?.getPersistentValue(name) 
     def newValue = domain?.otherDomain?."$name" 
    } 

Но я получаю Нет такого свойства: dirtyPropertyNames для класса: otherDomain

ответ

1

Это, похоже, не проблема при тестировании против 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 
} 

Хотя, аппроксимируемостью 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) 
+0

Привет Я с использованием граблей 1.3.7 – Apu

Смежные вопросы