Support > Repository > Parent-child relationship

Wagby defines the relationship "parent" model and "child" model using foreign keys.

In Wagby, the idea of ​​"foreign key" is prepared to realize "there is more than one data in one data" relationship. Specifically, it looks like Figure 1.

Figure 1 Image of parent-child relationship

Here, when expressing the main model as "parent" and the model dependent on parent as "child", the following relation holds for parent and child.

  • The parent model and the child model can refer to each other.
  • The parent model is "reference destination".The child model is "reference source".The child model has the key of the parent model, which is called the "foreign key".
  • Multiple child models can be linked to one parent model.(1: N relationship)
  • You can handle child models independently.More specifically, it is possible to perform a search and display processing of a child model.
  • If the parent model is deleted, child models can also be deleted at the same time.(You can dare to leave.)
(1) Defining a parent-child relationship
We deal with two models "customer" and "support". At this time, we have a relationship that "There is more than one support record for one customer". Parent is customer (1), child is support (N).
(2) Link multiple children to one parent
We will show an example of preparing two child models "customer" as parent model and "support" "buying".
(3) Make sure that you can not create a child model unless the parent model exists
Prepare a new registration button for the child model on the details screen of the parent model. Also, a child model new registration button is not prepared on the child model side. This realizes the operation that the (parents) parent always exists when there is child data .
(4) Allow creation of child models without parent model
It is operation not specifying a parent parent model when new child model is registered. Parents can be selected later if necessary.
(5) Link multiple parents to one child
I will explain an example of a child model "warehouse stock" that refers to two parent models "warehouse" and "item".
(6) Setting related to cooperation
We introduce the option to set on the child model side.
(7) Simultaneous update of child models
In foreign key relation, child model can be updated directly on the update screen of parent model.
(8) Display the child model list using item values ​​other than the parent key
The child model displayed on the parent model screen is usually narrowed down by the parent key. Specifying this condition individually makes it possible to display the child model list even if the parent key is not set yet.