| Author |
Grails / GORM: How to remove a relation from a M:N relation when deleting an entity?
|
Kai Wähner
Ranch Hand
Joined: Sep 16, 2009
Posts: 74
|
|
Hi,
I have the following situation: A project has several employees. An employee is assigned to several projects. There is no "belongsTo"-cascade because if I delete a project or
an employee, I do not want to delete the other one, of course. Two questions:
1) How do I remove the relations in the table project_employee if I delete the employee? If I use the "belongsTo"-cascade, then the table project_employee would be empty, but the project
would be deleted, too ?!
Do I have to do it manually by getting all projects of the employee,
and then remove the employee from every employee-list of each project? There should be an easier way?
2) A project has sub-projects (self referencing hasMany-relationship). The sub-project also has a M:N relation to employees. I want to realize a constraint, so that
an employee may only be within a sub-project if he is also assigned to the main project. How do I realize this constraint?
Thanks a lot for help...
Best regards, Kai
|
My IT-blog about my experiences with: Java / JEE, IT Conferences and IT Certifications
|
 |
Gregg Bolinger
Sheriff
Joined: Jul 11, 2001
Posts: 15040
|
|
|
I find it kind of difficult to follow you. The best thing would be to show us your domain classes to compliment your description of the problem.
|
My Blog | DZone Articles
|
 |
Kai Wähner
Ranch Hand
Joined: Sep 16, 2009
Posts: 74
|
|
Ok, I will explain with the domain classes.
These domains create these tables: "projekt", "employee", "project_employee" for the M:N relationship, and "project_subproject"
1) How do I delete an employee and the entries within project_employee, but not the project?
2) Project has Sub-Projects. I need a constraint, so that an employee may only be member of a sub-project, if it also is a member in the main project already.
I hope you can follow me now, viewing the two domains?
|
 |
 |
|
|
subject: Grails / GORM: How to remove a relation from a M:N relation when deleting an entity?
|
|
|