Question

I'm having some problems with the GORM part of Grails. I am using Grails 1.3.4, together with H2.

In the database I have two tables template and report. On the GORM-level I have the two Domain classes Template and Report;

class Template {

static hasMany = [reports: Report]

...
}

and

class Report {

static belongsTo = [template: Template]

...
}

Default behaviour seems to be that when a Template is deleted, the deletion will be cascaded so that all Reports that it has will be deleted as well. On the database level I tried to make the template_id-column in the report-table be a ON DELETE SET NULL foreign key , but that didn't work.

Is there some way to override the cascade delete?

Was it helpful?

Solution

The following should be added in the Template class:

static mapping = {
  reports cascade: 'none'
}

to be able to delete Templates without problems, this addition to the Report class is also necessary:

static constraints = {
  template(nullable: true)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top