级联“向上”有意义吗?属于属于关系的所有者?

发布于 2024-09-25 03:33:13 字数 413 浏览 3 评论 0原文

  • 我有一个技能类,其中有很多角色技能。
  • 我有一个 RoleSkills 类,它属于角色和技能
  • 我有一个 Role 类,它有许多 RoleSkills

对于角色,我有一个将操作级联到 RoleSkills 的映射。问题是,RoleSkills“级联”回Skill有意义吗?

我基本上想让 RoleSkill 在创建时创建一项新技能,但如果 R​​oleSkill 被删除,请保留 Skill 类(它们基本上是相同的,但一旦一个人创建了 RoleSkill,我希望该技能可供其他人使用)使用)。

在grails中,每当我创建一个新角色并为其分配一个RoleSkill时,我都会收到一条有关RoleSkill.skill为空的消息,因此我需要找到一种方法来级联“向上”以在创建新RoleSkill时创建新技能。

  • 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空名 2024-10-02 03:33:13

我认为您需要向 RoleSkill 构造函数添加一些逻辑。我不确定这在实践中如何运作,但理论上您可以尝试类似的操作:

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.
   }
}

请仔细检查 参考文档,同时尝试此实现。希望它能为您指明正确的方向。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文