this is a pretty strange issue.
I have a many-to-many relationship between two classes, Subscription & Scenario. Thing is I'm trying to delete the relation between them when either is deleted using "beforeDelete" in each of these classes.
ScenarioSubscription is the class representing the junction table.
This is what my beforeDelete def looks like in Scenario.
def beforeDelete = {
//Delete rows 开发者_运维知识库in junction table
def example = new ScenarioSubscription(scenarioId:id)
def scenSub = ScenarioSubscription.findAll(example)
scenSub*.delete(flush:true)
}
It works in the Subscription class but not in Scenario. Instead, when calling *.delete() the "beforeDelete" def is called recursively. I checked the variable when debugging and scenSub is a list of ScenarioSubscription. Crazy?!
Any idea of what is going on is very much appreciated.
So, it sounds like your ScenarioSubscription
domain object has two properties, Scenario
and Subscription
. When you try to delete the link domain object, it tries to cascade the delete down to the Scenario
which fires the beforeDelete
closure (and repeats till crash)
I think you'll need to define a custom cascade mapping for your ScenarioSubscription
properties, or, couldn't you define a custom mapping for this Scenario
domain object, and get rid of your beforeDelete
entirely?
ie:
static mapping = {
subscriptions cascade:"all-delete-orphan"
}
This question might be of help as well
精彩评论