Search code examples
hibernategrailsgrails-orm

Grails hasOne Relationship without belongsTo


When going through documentation to work on hasOne relationship without belongsTo it throws an error

hasOne property [Face.nose] is not bidirectional. Specify the other side of the relationship!.

Its just an example, in my usecase if i delete the nose i should not delete the face.So how to make it work without using belongsTo?

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

Solution

  • I think your path here is to not use the hasOne keyword.

    class Face {
      Nose nose
    }
    
    class Nose {
      Face face
    }
    

    Either can exist independently of the other, but both have references to each other.