Issue Details (XML | Word | Printable)

Key: GRAILS-3033
Type: Sub-task Sub-task
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Graeme Rocher
Reporter: Tyler Williams
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Grails
GRAILS-3396

One-to-many - 'belongsTo' incompatible with 'joinTable'

Created: 30/May/08 05:23 PM   Updated: 21/Jan/09 09:03 AM   Resolved: 21/Jan/09 09:03 AM
Return to search
Component/s: Persistence
Affects Version/s: 1.0.2
Fix Version/s: 1.1-beta3

Time Tracking:
Not Specified


 Description  « Hide

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'



Jens Lukowski added a comment - 02/Dec/08 06:32 AM

If you use cascade as a workaround for belongsTo, the validation does not cascade.