Support > Repository > Parent-child relationship > Defining a parent-child relationship
ja | en

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).

Let's take a look at two models, "customer" and "support".

Register new customer's data.
The "Support new creation" button is prepared on the detail display screen of the customer.(Figure 1) To register a support model that is related to a foreign key, perform the new registration from the detail display screen of the target data (here, customer data).

Figure 1 Customer details display screen

Click the "Create new support" button and open the support new registration screen.The customer ID (ID of the linked parent model) is automatically set.

Figure 2 Support new registration screen

Enter each item and register."Customer list display" and "Customer details display" button for returning to the customer model from the support detailed display screen are prepared.

Figure 3 Support detail screen

Click the "Customer details display" button to open the customer details display screen.A list of support records will be displayed on the customer model side as well.

Figure 4 Customer Detailed Display Screen

In this way, models that are related to foreign keys also have bidirectional link relationships on the screen.This will allow you to check "which records were supported by which customers".

In the foreign key relationship, at the timing when the customer's data is deleted, all support data related to it is also deleted.(You can change this behavior and set support data to not delete at the same time.)

The definition of the support model prepared this time is shown in Figure 6.
Specify the type of the item specified as the foreign key with the same type as the type of the reference (parent) item.In this example, "customer ID" is specified as "numeric" type.

Figure 6 Definition of support model

The point of definition is the part that specifies that "customer ID" is a foreign key.(FIG. 7)
Specify the parent model for "foreign key> model name".

Figure 7 Defining Foreign Keys

"Referenced item name" is the item on the child model side isSame nameCan be omitted.(This time it is the same "customerid", so you can omit it.)

Figure 8 Definition of foreign key (when referencing item name is omitted)

When the external key model list display format is grid, the child model display will also be grid.

Figure 9 Grid display of child model

The grid display has several limitations.For details, see "Screen function> Search/List display (list display) Grid formatPlease read.

Foreign key Chain icon is displayed in the model item list for the specified item.

Figure 9 Chain icon is displayed

The display order of the child model list prepared at the bottom of the parent model's detailed display screen is the ascending order of the child model primary key. You can change this.

For example, when you create children c1, c2, c3 for parent p1, the display of the child model's screen is c1, c2, c3 by default. If "-1" is specified here in the sort order of the child model "primary key" item, it becomes c 3, c 2, c 1.

For details, see "Model definition> sortPlease read.

The sort setting is reflected not only in the child model display of the parent-child model screen but also in the list display screen of the child model.(Both are not distinguished)

"Repeat container"And" 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.

Child model list is not displayed

"Screen> Search/list display> Foreign key cooperation> List of data to be displayed on the detailed display screen of the parent modelPlease make sure the setting of "Enable" is enabled.