0
votes

I have two domain classes in grails. One is called Book and the other is called Author. My Book class looks like this,

class Book {
   String name

   static constraints = {
      name nullable:false
   }
}

And My Author class:

class Author {
   String name
   Book book1
   Book book2
   Book book3

   static constraints = {
      name nullable:false
      book1 nullable:false
      book2 nullable:true
      book3 nullable:true
   }
}

Ff I create an author with two books and then edit it to one book I got the following error:

identifier of an instance of com.apps.Book was altered from 2 to null

How to fix it? I am using grails 2.1.1 and sql server 2008.

2

2 Answers

1
votes

try set to null book2 and book3 properties before the line authorInstance.properties = params in the update method like this:

book2 = null
book3 = null

authorInstance.properties = params
0
votes

try using 'hasOne' in Author class:

class Author {
   String name
   Book book1, book2, book3
   static hasOne = [ book1:Book, book2:Book, book3:Book ]
}