In JHipster how to create entity with relationship with User?

℡╲_俬逩灬. 提交于 2019-11-30 08:21:15

Just an update - jhipster 2.5.0 was released a few days ago adding support for this. Created this answer since the formatting in comments make i pretty hard to read.

When creating a relation for your entity simply answer the questions like this

? 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

Possible values on how to display the relation could be: id, login, first_name, last_name, email

See https://jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html for moreinformation

Just to add to the correct answer by @stoffer, if you're using the jdl it will look like:

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

If you are using the 1.x version, this wasn't made to work, so basically you should do it by hand, without the generator (but it is definitely doable). For the 2.x version, we have refactored the User object to have an ID field -> this should make this a lot easier, but as this is not released yet, we don't have a feedback at the moment.

at a good sample in an official document is say :

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

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

jdl-samples/blog.jh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!