I am trying to set up a few domain classes. I will explain it in english, and I am wondering how the domain would be set up in grails. Capitalized words are my domains
An Employee has an Education. An Employee has many Employer (past and present). An Employee had one or many Project for each Employer. Project have a Role, Client…etc
Now my question is, when for example, I define Employer, will I put
hasMany = [projects:Project]
and ALSO in Project put
belongsTo = [employer:Employer, employee:Employee, client:Client]
Mind you – many employees may have worked on the same project, so I might want to figure out a way to define that?
Would I also put in Employer:
ArrayList<Project> project = new ArrayList();
static hasMany = [projects:Project]
Or is that redundant?
Variable declaration is not the same as defining a
belongsTorelationship.belongsTomostly comes into play with cascading of persistence actions, notably deletes. For example, if you have two classes:If a specific Project belongs to an Employee, and that Employee is deleted, the Project will also be deleted. Here’s another SO question with a good answer.
For your second question, yes, defining the
Listis redundant. If you do:The Collection is implicitly defined for the domain. However, there are certain cases where you may need to initialize the Collection for use within
constraints. See this issue for more details.