Grails

bidirectional one-to-one relation did not save child objects when constructor isn't used

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 2.0 final
  • Fix Version/s: 2.0.1
  • Component/s: Persistence
  • Labels:
    None

Description

Using your nose / face example for a one-to-one relationship, I created two classes:

class Face {
    static hasOne = [nose: Nose]
}

class Nose {
    Face face
}

What I expected to happen is when creating a Face object and assign a Nose object to it, both will be saved:

(1)
    Face face = new Face()
    Nose nose = new Nose()
    face.nose = nose
    face.save()

This isn't working, but this is:

(2)
    Face face = new Face()
    Nose nose = new Nose()
    face.setNose(nose)
    -- *NEW* --> nose.face = face
    face.save()

And this (what I really don't understand):

(3)
    Face face = new Face(nose: new Nose()).save()

I don't understand, why (3) works as expected, (1) is not. It seems, that because of the bidirectional one-to-one relation the nose object isn't valid (nose.validate() => false), because in (1) I did not assign the face to the nose object, as in (2), but in (3) this is done automatically.

Issue Links

Activity

Hide
Daniel Plappert added a comment -
Show
Daniel Plappert added a comment - This issue is related to: http://jira.grails.org/browse/GRAILS-8451
Hide
Graeme Rocher added a comment -

closing as duplicate, please watch GRAILS-8451

Show
Graeme Rocher added a comment - closing as duplicate, please watch GRAILS-8451

People

Vote (3)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: