Link Domain Objects in Grails without cascading deletes

How do I link two domain classes in Grails without having the deletes cascade from one to another? I have two domains which are related, but one is not intrinsically superior to the other. This is basically the idea:

class Project{
    static hasMany = [workers:Employe]
}


class Employe{
    static hasMany = [jobs:Project]
}

If a certain project gets closed down all of the workers shouldn't be deleted, and if one worker quits his jobs he shouldn't be deleted either.

Answers


You could split up the domains:

class Project{

   def getWorkers() {  
    EmployeeProject.findAll("from EmployeeProject as e where e.project.id=?", [this?.id], [cache: true])
   }
}

class Employee {

    def getProjects() {
      EmployeeProject.findAll("from EmployeeProject as ep where ep.employee.id=?", [this?.id], [cache: true])
   }
}

class EmployeeProject {    
  Employee employee
  Project project   
}

Then you can just use project.workers, employee.projects and delete the EmployeeProject objects without effecting the other classes.


Need Your Help

Toad/Oracle: Which role do I need to see all Tablespaces?

database oracle11g roles toad

I am currently trying to setup a new schema on an Oracle 11g RAC. I received a user and a corresponding schema and have full rights within my schema.