【问题标题】:In JHipster how to create entity with relationship with User?在 JHipster 中如何创建与用户有关系的实体?
【发布时间】:2015-03-08 21:13:30
【问题描述】:

我需要使用 JHipster 使用命令“yo jhipster:entity myEntity”创建我自己的实体,这些实体与 JHipster 中默认提供的用户实体具有多对一关系。

我尝试在向导中创建与实体“用户”和字段“登录”的关系,但没有成功。

用 JHipster 做这件事的好方法是什么?还是我必须在没有 JHipster 工具的情况下创建实体(但我需要 CRUD!)。

谢谢,

亚恩

【问题讨论】:

    标签: jhipster


    【解决方案1】:

    只是一个更新 - 几天前发布了 jhipster 2.5.0,增加了对此的支持。创建此答案是因为 cmets 中的格式使我很难阅读。

    为您的实体创建关系时,只需回答这样的问题

    ? Do you want to add a relationship to another entity? Yes
    ? What is the name of the other entity? user
    ? What is the name of the relationship? owner
    ? What is the type of the relationship? many-to-one
    ? When you display this relationship with AngularJS, which field from 'user' do you want to use? login
    

    关于如何显示关系的可能值可能是:id、登录名、名字、姓氏、电子邮件

    更多信息请参见https://jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html

    【讨论】:

    • 是否可以与用户实体使用一对多关系?我想创建一个“公司”实体,一个与多个用户相关的公司。如何用 jhipster 实现它?
    • 但是如何从用户实体端创建关系呢?找不到 xml 文件,因为该实体是在 initial_schema 文件中创建的,并且不是独立实体。
    【解决方案2】:

    只是为了添加@stoffer 的正确答案,如果您使用的是 jdl,它将如下所示:

    relationship ManyToOne {
        Owner{user(email)} to User{owner(name)}
    }
    

    【讨论】:

      【解决方案3】:

      如果您使用的是 1.x 版本,则无法正常工作,因此基本上您应该手动完成,无需生成器(但绝对可行)。 对于 2.x 版本,我们已将 User 对象重构为具有 ID 字段 -> 这应该会更容易,但由于尚未发布,我们目前没有反馈。

      【讨论】:

      • 只是一个更新 - 几天前发布了 jhipster 2.5.0,增加了对此的支持。简单地创建关系时?是否要向另一个实体添加关系?是的 ?另一个实体的名称是什么?用户?关系的名称是什么?所有者 ?关系的类型是什么?多对一?当您使用 AngularJS 显示这种关系时,您想使用“用户”中的哪个字段?登录名(此处可能的值可能是;id、登录名、名字、姓氏、电子邮件)有关信息,请参阅jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html
      【解决方案4】:

      官方文档中有一个很好的示例:

      entity Blog {
          name String required minlength(3),
          handle String required minlength(2)
      }
      
      relationship ManyToOne {
          Blog{user(login)} to User 
      }
      
      

      jdl-samples/blog.jh

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-21
        • 2016-06-19
        • 2022-07-19
        • 2018-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多