gorm - Explain belongsTo in Grails -


from grails belongsto documentation, use of

   class book {     static belongsto = author } 

what impact of cascading operations on book, when crud operations performed on author?

edit:

thanks responses, may didn't specify question correctly. know difference between

 static belongsto [author:author] 

vs

 static belongsto = author 

belongsto helpful if need reference owning object. in case author has many books. maybe you're using book object , want mention book instance's author. way it.

as far crud goes, deleting or updating book not author, deleting author delete book. if don't add belongsto there no cascading saves/updates/deletes, have manually.

example:

def = new author(name: 'j.k. rawling') a.addtobooks(new book(title: 'harry potter 1')) a.addtobooks(new book(title: 'harry potter 2')) a.save()   // saves author , book instances  a.delete() // author , both books deleted 

edit:

the op updated question, , i'm not sure answer be. burt beckwith show soon! question, op.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -