barmaleikin
barmaleikin

Reputation: 463

Unable to save object to database with save(flush : true)

Here are my simple domain classes:

package family

class Parent {

    static hasMany = [children : Child]
    String name 
}

package family

class Child {
    static belongsTo = [parent : Parent]
    String name
}

In the BootStrap I do following:

import family.Child;
import family.Parent;

class BootStrap {

    def init = { servletContext ->

        def parent = new Parent(name:'Dad')
        parent.addToChildren(new Child(name:'son'))
        parent.addToChildren([name : "another son"])
        parent.save(flush : true, failOnError : true)

        println "hasErrors: " + parent.hasErrors()
        println "Parent: " + parent.name + " Children: " + parent.children.count()
    }

    def destroy = {
    }
}

And in the console I see: hasErrors: false Parent: Dad Children: 0

Could you please help me to understand why children is always 0? What am I doing wrong?

Upvotes: 0

Views: 702

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

It should be size() not count().

Upvotes: 2

Related Questions