I will explain Wagby's "parent-child relationship" definition method.

Wagby allows you to set parent-child relationships in your model.

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.
  • Multiple child models can be linked to one parent model.
  • Multiple parent models can be linked to one child model.
  • 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.)

In this tutorial, you will learn how to set up a parent-child relationship.

We prepare a "support" model which is a child model dependent on this customer model as a parent. Support can be registered multiple times for one customer.

Item name (Japanese) Item name (English) Item type Primary key Foreign key
Support ID supportid Integer type
Customer ID customerid Integer type
date supportdate Date type
title title String type
Support type supporttype Item reference of another model (list box)
Contents content String type

Create a new model.

Figure 1 Creating a new model

We will name the model "support".Suppose the model ID is "support".

Next to the primary key item "support ID", prepare the foreign key item "customer ID".
The item ID is the same as the item ID (customerid) of the customer model.
Type is always the same (numerical type here).

Figure 2 Definition of support ID and customer ID

In the detailed setting of customer ID, set the column of foreign key.Designation of the model name is mandatory.
The referenced item name is "It is specified when the item ID's name is different. Since this time it is the same item ID (customerid), designation is unnecessary.(It will be automatically discriminated.)

Figure 3 Foreign key setting

Define the remaining items.In this case, "support type" is a character string type.(Because the alternative model of the reference has not been created yet)

Figure 4 Definition of support model

Prepare a new option model "support type".We also set the initial value.(FIG. 5, FIG. 6, FIG. 7)

Figure 5 Creating a selection model
Figure 6 Preparing a support type model
Fig. 7 Preparing initial values

Again you will return to the support model edit screen.Change the type of support type to "reference item of other model".(FIG. 8, FIG. 9)

Figure 8 To the support model edit screen
Figure 9 Change in type

Associate with the support type model prepared in Figure 6.

Fig. 10 Setting the reference model

Indicates the finished model definition.(FIG. 11)

Figure 11 Definition of support model

As before, I stop, build, and restart the Web application. After logging on to the application, import historical data.

Opens the detailed display screen of an arbitrary customer model.New "Support new creation" button is prepared.

If you do not see this button,Repository> Foreign key> Settings related to cooperation> Control display of buttonPlease check the setting of ".
Figure 12 Support New Create Button

I will try creating a new support.The customer's primary key (customer ID), which is the parent model, is automatically granted.

Figure 13 Creating a new support

On the detailed support screen of the support, buttons for transitioning to the list display / detail display screen for the parent model customer are provided.

Figure 14 Detailed display of support

In the detail display screen of the customer, N support information related to this is displayed.(1: N relationship)

Figure 15 Customer Detail Display Screen

Both the "repeating container" and the "foreign key" can build a 1: N relationship between the parent model and the child model.The difference between the two is as follows.

  • Repeated containers mean "items" in the parent model.It has strong dependency with the parent, and it is deleted automatically when the parent is deleted.
  • A foreign key means there is something related to parent and child.It has no strong dependency as repeating containers, and it can also do its own search processing on the child model side.

In the tutorial so far, the three models "customer", "business daily report" and "support" are linked in different ways.This is shown in Figure 18.


Figure 17 Model linkage drawing

"Frequently asked questions and answers> tutorialPlease read.