I have two domain classes User and Node. The following conditions should hold.
- a User can have zero or one node
- a Node can have one to n User (it is always initialized with a User instance)
- if you delete a Node the User will not be deleted
- if you delete a User the reference in the Node will be deleted
I tried:
class User {
Node node
}
class Node {
// constructor
Node(User user) {
addToUsers(user)
save()
}
hasMany = [users: User]
}
The former does not work. It does not work because when you delete a node there is a dependent reference in the user instance that will not be delete automatically.
How can I model the domain classes in this case?