Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JHipster how to create entity with relationship with User?

Tags:

jhipster

I need to create my own entities using the JHipster using the command "yo jhipster:entity myEntity" that have many-to-one relationship with the User entity that comes by default in JHipster.

I have tried unsuccessfully to create in the wizard a relationship with the entity "user" and the field "login" but it is not working.

What is the good way to do this with JHipster? Or do I have to create the entity without JHipster tool (but I need the CRUD!).

Thanks,

Yann

like image 252
Yann Nicolas Avatar asked Jan 10 '15 17:01

Yann Nicolas


People also ask

How do you create a many to many relationship in JHipster?

If you want to create many entities and relationships, you might prefer to use a graphical tool. In that case, two options are available: JHipster UML, which allows you to use an UML editor. JDL Studio, our online tool to create entities and relationships using our domain-specific language.

What is the name of the relationship JHipster?

All the relationships use the default JPA FetchType: OneToMany: LAZY. ManyToOne: EAGER. ManyToMany: LAZY.


2 Answers

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

like image 135
stoffer Avatar answered Oct 13 '22 13:10

stoffer


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)}
}
like image 12
j.davies Avatar answered Oct 13 '22 11:10

j.davies