Reputation: 57192
I have 2 domain classes
class A {
static hasMany = [ b : B ]
}
class B {
static belongsTo = A
}
I would like to keep the cascading saves, so when I save A, it updates the B's, but when I do a delete of A, I would like it to fail if any B's exist that are associated with that A. So you would have to explicitly delete all of the B's first.
I'm not sure the easiest way to do this in Grails. I could put a check in A before I delete it to verify that there are no B's - simple enough. But is there a way to control this through cascading or relationship behaviors so I don't have to put the logic in there?
Upvotes: 1
Views: 479
Reputation: 4096
Specify the cascade behavior for the collection
class A {
static hasMany = [ b : B ]
static mapping = {
b cascade: 'save-update'
}
}
It will cascade save and update but not delete.
Upvotes: 1