在JHipster中如何创建与User有关系的实体?

Yan*_*las 21 jhipster

我需要使用命令"yo jhipster:entity myEntity"使用JHipster创建我自己的实体,该命令与JHipster中默认出现的User实体具有多对一关系.

我尝试在向导中创建与实体"user"和字段"login"的关系但没有成功,但它无法正常工作.

用JHipster做这个的好方法是什么?或者我是否必须在没有JHipster工具的情况下创建实体(但我需要CRUD!).

谢谢,

sto*_*fer 18

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

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

? 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
Run Code Online (Sandbox Code Playgroud)

关于如何显示关系的可能值可以是:id,login,first_name,last_name,email

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


j.d*_*ies 8

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

relationship ManyToOne {
    Owner{user(email)} to User{owner(name)}
}
Run Code Online (Sandbox Code Playgroud)


小智 5

官方文件中的一个很好的示例是:

entity Blog {
    name String required minlength(3),
    handle String required minlength(2)
}

relationship ManyToOne {
    Blog{user(login)} to User 
}

Run Code Online (Sandbox Code Playgroud)

jdl-样本/blog.jh


Jul*_*ois 4

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

  • 只是一个更新 - jhipster 2.5.0 几天前发布,添加了对此的支持。简单地创建关系时?您想添加与另一个实体的关系吗?是的 ?另一个实体的名称是什么?用户?该关系的名称是什么?所有者 ?关系的类型是什么?多对一?当你用 AngularJS 显示这种关系时,你想使用“用户”中的哪个字段?登录(此处可能的值可以是:id、login、first_name、last_name、email)有关信息,请参阅 https://jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html (2认同)