How to create multiple FK from one table reference same column of other table using JDL?

75 Views Asked by At

There are two tables Period_Type & Product_Subscription

Period_Type 
->ID
->Period_Type_Name
---------------------------------------
Product_Subscription
-> RENEWAL_PERIOD_TYPE_ID
-> SUBSCRIPTION_PERIOD_TYPE_ID
----------------------------------------
-> FOREIGN KEY (RENEWAL_PERIOD_TYPE_ID) REFERENCES PERIOD_TYPE(ID)
-> FOREIGN KEY (SUBSCRIPTION_PERIOD_TYPE_ID) REFERENCES PERIOD_TYPE(ID)

How to implement the above schema using JDL?

1

There are 1 best solutions below

3
Gaël Marziou On

Please read the doc: https://www.jhipster.tech/jdl/relationships about JDL syntax and also there is an example which is exactly your use case: https://www.jhipster.tech/managing-relationships/#two-one-to-many-relationships-on-the-same-two-entities

You must indicate the relationship name in the relationship definition so that it is used for both the entity's field for the name of the foreign key in Liquibase changelog.

entity PeriodType {
    periodTypeName String
}

entity ProductSubscription {
}

relationship ManyToOne {
    ProductSubscription{renewalPeriodType} to PeriodType
    ProductSubscription{subscriptionPeriodType} to PeriodType
}

Additionally, you can also specify which field to use for display in frontend.