Relationships

Now that we have defined our entities, let's add relationships between them:

  1. Add the following snippet for relationships into the JDL-Studio editor:
relationship OneToOne {
Customer{user} to User
}

The first relationship declared is a unidirectional OneToOne between a Customer entity and the inbuilt User entity: 

Customer (1) -----> (1) User

It means that the Customer entity knows about the User and is the owner of the relationship, but the User doesn't know about the Customer, and so we will not be able to obtain customers from a User. This lets us map customers to the User entity and use it for authorization purposes later, ensuring that one customer can be mapped to only one system user.

  1. Add the following snippet for relationships into the JDL-Studio editor:
relationship ManyToOne {
OrderItem{product} to Product
}

This one declares a unidirectional ManyToOne relationship from OrderItem to Product

OrderItem (*) -----> (1) Product

This means that the OrderItem knows their Product, but the Product does not know about the OrderItem. This keeps the design clean as we don't want to know about orders from products for this use case. In the future, if we want to know the orders that have been made for a product, then we could make this bidirectional. 

  1. Add the following snippet for a relationship into the JDL-Studio editor:
relationship OneToMany {
Customer{order} to ProductOrder{customer},
ProductOrder{orderItem} to OrderItem{order},
ProductOrder{invoice} to Invoice{order},
Invoice{shipment} to Shipment{invoice},
ProductCategory{product} to Product{productCategory}
}

This declaration is interesting, as we have multiple OneToMany declarations:

Customer (1) <-----> (*) ProductOrder
ProductOrder (1) <-----> (*) OrderItem
ProductOrder (1) <-----> (*) Invoice
Invoice (1) <-----> (*) Shipment
ProductCategory (1) <-----> (*) Product

They are all bidirectional, meaning that both the source entity and the destination entity know about each other.

We declare that a Customer can have multiple instances of ProductOrder, ProductOrder can have multiple OrderItem and invoices, Invoice can have many instances of Shipment, and ProductCategory can have many products. From the destination entity, the source entities are mapped as ManyToOne.

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

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