If I have the following two classes:
class Employee {
static hasMany = [projects: Project]
static mapping = {
projects joinTable: [name: 'EMP_PROJ', column: 'PROJECT_ID', key: 'EMPLOYEE_ID']
}
}
class Project {
static belongsTo = Employee
}
I expect three tables (EMPLOYEE, PROJECT, EMP_PROJ), but instead of EMP_PROJ I get EMPLOYEE_PROJECT. It ignores the joinTable:name parameter (but not the column or key parameters). The reason is the belongsTo clause in Project. If I remove the belongsTo then I get EMP_PROJ as I wanted, but now Employee.delete() doesn't cascade to the related Projects. The workaround is to explicitly define the cascade behavior using something like:
projects joinTable: [name: 'EMP_PROJ', column: 'PROJECT_ID', key: 'EMPLOYEE_ID'], cascade: 'all,delete-orphan'
If you use cascade as a workaround for belongsTo, the validation does not cascade.