0

Here are the domain classes

class Settings {
    static constraints = {
        uid(nullable: false, unique: true)
        data()
    }
    static hasMany = [items: Item]
    Map data
}

class Item{

    static constraints = {
        name()
        email()
        approved()
    }

    static mapping = {
        email index: true, indexAttributes: [unique: true]
    }

    String name
    String email
    Boolean approved = false;
}

Basically there are many Settings objects that have many items (see illustration below): Data Structure

Now I'm finding and updating an item like so:

...
        def item = (Item)Item.findByEmail(email);
        if (!item.approved) {
            item.approved = true;
            item.save(flush: true);
        }
...

Not Saved what am I missing here?

Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186

1 Answers1

0

MongoDB does not except null fields by default. Once I've added a value all works well:

...
    def item = (Item)Item.findByEmail(email);
    if (!item.approved) {
        item.approved = true;
        item.name = "MyName";
        item.save(flush: true);
    }
...
Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186