Reputation: 533
I'm currently working with Grails 1.3.7, and I have the following domain classes connected by a pair of one-to-one relationships:
class Parent {
Child child1
Child child2
static constraints = {}
}
and
class Child {
static belongsTo = [parent:Parent]
static constraints = {}
}
In a separate service class, I have the following method:
def checkParent(child) {
log.info(child.parent)
}
Lastly, in my controller, I have the following code:
Parent parent = new Parent()
parent.child1 = new Child()
parent.child2 = new Child()
parent.save(flush:true)
childService.checkParent(parent.child1)
childService.checkParent(parent.child2)
My log output shows me that one of the Child
objects always has a null reference to parent
, whereas the other has the backreference established as expected.
Why does this happen?
Upvotes: 2
Views: 697