Relationship management

The relationship between entities can be declared using the following syntax:

relationship <type> {
<from entity>[{<relationship name>[(<display field>)] <validation>*}]
to
<to entity>[{<relationship name>[(<display field>)] <validation>*}]
}

The <type> can be OneToMany, ManyToOne, OneToOne, or ManyToMany, and as the name suggests, declares the relationship type between <from entity> and <to entity>.

The <from entity> phrase is the name of the owner entity of the relationship or the source. The <to entity> phrase is the destination of the relationship.

The <relationship name> phrase is optional and can be used to specify the field names to be created for the relationship in the domain object. The <display field> phrase can be specified in braces to control the field of the entity to be shown in the drop-down menu on the generated web page; the ID field will be used by default. The <validation> phrase can be specified on the <from entity> or <to entity> and is optional. Currently, the only supported validation is required.

Relationships that are labelled as OneToMany and ManyToMany are always bidirectional in JHipster. In the case of ManyToOne and OneToOne relationships, it is possible to create both bidirectional and unidirectional relationships. For unidirectional relationships, just don't enter a <relationship name> on the destination/to entity.

Multiple relationships of the same type can be declared within the same block, separated by a comma.

An example relationship declaration would look like the following:

entity Book
entity Author
entity Tag

relationship OneToMany {
Author{book} to Book{writer(name) required},
Book{tag} to Tag
}

The user is an existing entity in JHipster, and it is possible to have certain relationships with the user. Many-to-many and one-to-one relations can be declared, but the other entity must be the source or owner. Many-to-one relationships are also possible with a user entity.

Let's learn about Data Transfer Objects (DTO), service, and pagination options in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.120.109