views:

76

answers:

0

Hi,

Using Grails (GORM) I'm populating a collection upon creating an object and I must return the newly populated collection with ids.

class A { static hasMany = [bees:B] }
class B { static belongsTo = [a:A] }

As noticed, a one-to-many relationship when the many side belongs to the one side for full cascading

If A is not saved before:

println new A().addToBees(new B()).save().bees // prints [B : 1]

But if A is already saved:

def a = new A().save()
println a.addToBees(new B()).save().bees // prints [B : null]

What is the proper way to get the newly created ids when the one side is already saved?

Thanks, Guy