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
posted
0
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?
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?
This message was edited 1 time. Last update was at by Kai Wähner
subject: Grails / GORM: How to remove a relation from a M:N relation when deleting an entity?