- I have a Skill class, which hasMany RoleSkills.
- I have a RoleSkills class which belongsTo Role and Skill
- I have a Role class which hasMany RoleSkills
For Role, I have a mapping that cascades operations to RoleSkills. The开发者_开发百科 question is, does it make sense for RoleSkills to "cascade" back to Skill?
I basically want to have a RoleSkill create a new skill when it is created, but if RoleSkill gets deleted, leave the Skill class (they are basically the same, but once one person makes a RoleSkill I want that Skill the be available for other people to use).
In grails, whenever I make a new Role, and assign it a RoleSkill I am getting a message about RoleSkill.skill being null, so I need to find a way to cascade "up" to create a new Skill whenever a new RoleSkill is made.
I think you would need to add some logic to the RoleSkill constructor. I'm uncertain of how this will work in practice, but in theory you could try something like:
class Skill {
String name
static hasMany = [roleSkills:RoleSkill]
}
class Role {
String name
static hasMany = [roleSkills:RoleSkill]
}
class RoleSkill {
static belongsTo = [role:Role,skill:Skill] //I don't think this works based on the reference docs.
public RoleSkill() {
skill = new Skill() //This can later be changed to an existing Skill.
}
}
Please double check the reference documentation while trying this implementation. Hopefully it points you in the right direction.
精彩评论