Skip to content

relationships

Satish Sharma edited this page Jul 10, 2018 · 1 revision

Managing Associations and Relationships within Magic-Compose

In this section you will learn how to create the relationships between entities in Magic-Code format.

__Note: !!! caution

    These elements may vary according to the framework and tool selected for project. Currently these are specific to Spring Boot Data JPA and related frameworks.
    For more deeper dive of the associations please visit  [hibernate documentation](https://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/associations.html)

 **Do not use blank spaces and special characters in any of values for these element using which may cause failure in application generation.**

** relationships **

!!! note "" Possible Value : NA

This is the parent element for defining entites and pojos in ***Magic-Compose***. You will always define your entities or DTO/POJO whithin this tag.

** relationType **

!!! note "" Possible Value : ONETOONE/ONETOMANY/MANYTOONE/MANYTOMANY

The type of ***JPA Association*** you want to have between the entities.

bidirectional

!!! note "" Possible Value : true/false

Set this value to true if you want this relationship definition to be bi-directional

parent

!!! note "" **Possible Value : Any valid defined entity type in entities section **

This field defines which one of the two entities owns the relationship.
For example

Consider a scenario where a ***Student*** entity can have multiple ***Address***.
Here ***Student*** is going to be ***"parent"*** and ***Address*** is going to be ***"child"***

parentRelationshipName

!!! note "" Possible Value : any valid java identifier

  The name of the relationship given in parent/owning class.

parentJoinColumn

!!! danger "Added in Entities by framework" Possible Value : any valid java identifier

The name of the field to be used while performing joins. **Do not add this column while defining your entities, as this shall be added by the ***Magic-Code*** framework.**

child

!!! note "" **Possible Value : Any valid defined entity type in entities section **

This field defines which one of the two entities play's the role of child in the association mapping.
For example

Consider a scenario where a ***Student*** entity can have multiple ***Address***.
Here ***Student*** is going to be ***"parent"*** and ***Address*** is going to be ***"child"***.

childRelationshipName

!!! note "" Possible Value : any valid java identifier

  The name of the relationship given in child class.

childJoinColumn

!!! danger "Added in Entities by framework" Possible Value : any valid java identifier

The name of the field to be used while performing joins. **Do not add this column while defining your entities, as this shall be added by the ***Magic-Code*** framework.**

Managing Association/Relationships

JPA Entity associations to be created

JPA Entities

Database relationships which shall be created

JPA Entities

** Magic-Compose for relationships **

  "relationships": [
    {
      "relationType": "ONETOMANY",
      "bidirectional": true,
      "parent": "Student",
      "parentRelationshipName": "address",
      "parentJoinColumn": "address_id",
      "child": "Address",
      "childRelationshipName": "student",
      "childJoinColumn": "student_id1"
    },
    {
      "relationType": "ONETOONE",
      "bidirectional": true,
      "parent": "Student",
      "parentRelationshipName": "details",
      "parentJoinColumn": "details_id",
      "child": "StudentDetails",
      "childRelationshipName": "student",
      "childJoinColumn": "student_id2"
    }
  ]

Clone this wiki locally