Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPMONGODB-138: Modifications of embedded Lists are not saved when it is the only change in the object #110

Closed
graemerocher opened this issue Nov 17, 2011 · 0 comments

Comments

@graemerocher
Copy link
Member

Original Reporter: ziftytodd
Environment: Grails 2.0.0.RC1, OS X 10.7.2
Version: 1.0.0.RC1
Migrated From: http:https://jira.grails.org/browse/GPMONGODB-138

If you load an object, only add something to an embedded list in that object and do a save, the change to the embedded list is not saved if nothing else on the object changed. However, if you change a simple field on the object as well, then the change in the list is saved. For example:

{code:title=Author.java|borderStyle=solid}
class Author {
String id
String name
List books
Integer meaninglessField = 1
static hasMany = [ books : Book ]
static embedded = [ 'books' ]
}
{code}

{code:title=Book.java|borderStyle=solid}
class Book {
String title
String toString() { title }
}
{code}

{code:title=AuthorController.java|borderStyle=solid}
class AuthorController {
def addBookToAuthor() {
Author author = Author.get(params.id)
Book book = new Book(params)
author.books << book
log.info "in memory instance contains the added book: ${author.books}"
author.save(flush:true)

  Author loadedAuthor = Author.get(params.id)
  log.info "loading from mongo again shows the new book didn't get saved: ${loadedAuthor.books}"     

}

def addBookAndChangeAuthor() {
Author author = Author.get(params.id)
Book book = new Book(params)
author.books << book
author.meaninglessField++
author.save(flush:true)

  Author loadedAuthor = Author.get(params.id)
  log.info "loading from mongo again shows the new book did get saved when updating another field too: ${loadedAuthor.books}"     

}
}
{code}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant