×

Master detail

The master detail relationship depends on 2 tables. The tables are linked together by the primary key of the master table.

master table: er_customer

  • accountID, primary key
  • ...

detail table: er_employee

  • employeeID, primary key
  • accountID, master key
  • ...

The master detail form depends on 2 elements:

  • customer master data form
  • employee list

If the master form shows an empty or new record, the detail list must be empty too. A new record in the detail form is also not allowed.

If the master form displays a record, the detail element displays the list of the corresponding employees.

The rights of the detail list depend on the update right of the master record. If the update right of the master is granted, the rights: create, delete and update of the detail are also granted.

The master element triggers the detail element by the events: new and record click. Therefore we use the call back functions in JavaScript.

This 2 datadefinitions are created:

  • customermaster
  • employee

Master Customer

Datadefinition

customermaster.json

In the settingsadditional the second datadefinition for the employees is added.

The head_end adds the JavaScript file which is used to trigger the detail element.

Javascript

customermaster_head_end.js

SetArrayAll(...)

The header filters are set to false. The list is displayed without header filters.

pagesettings[]

This is an array with the detail elements:

  • settings: the datadefinition
  • mode: "masterdata","catalog","chartjs"

cbAfterNew

The showMasterDetail() function is called with the key=-1. The result is an empty detail list.

cbAfterLoad

The showMasterDetail() function is called with the accountID and the "rightuser_update". The corresponding employees are displayed. Without the update right of the master no new records can be added to the detail. Without the "rightuser_update" the controls "edit" and "delete" are hidden in the detail list.

Function showMasterDetail(...)

  • el_md: the detail element is appended to this HTML element
  • submode:
    • masterdata
    • catalog
    • chartjs
  • settingssub: the datadefinition of the detail
  • ID: the accountID of the master is the default value for the detail
  • rightuser_create: set to rightuser_update of the master

The detail element is created new by each time the function is called.

Delete records in child table

1. with foreigndeletions

Data definition: customermaster.json

The data access class will delete all records in the declared table where the childkey is equal to the key of the main table (er_customer).

2. with PHP include code

Data definition: customermaster.json

With the include file of the event "beforedelete" the corresponding records of the detail table are deleted with a PHP function. Here the PHP file to include is declared.

customermaster_beforedelete.php

This event is triggerd in the PHP backend, when a master record is deleted.

The variable "ID" contains the accountID value. With the SQL-Statement the corresponding records in the detail table are deleted too.

3. Delete records by database trigger

Data definition: customermaster.json

First the delimiters needs to be changed.

The trigger is build on the table er_customer with the event "AFTER DELETE".

For each deleted row the statements between BEGIN and END are executed.

The records with the condition: accountID = OLD.accountID are delete in er_customer.

At least the delimiters are changed back.

Detail employee

Datadefinition

employee.json

masterdatadefID

The CRUD rights depend on the master data definition.

masterkey

The masterkey is the detail column linked to the primary key of the master table.

edittype

The edittype is set to "3" for displaying the employee form as overlay.

bnoform

bnoform is set to true for displaying only the tabulator list.

rights

The method 2 (superuser) grants all rights to the superuser.

The method 1000 points to the master table. If the update right is granted for the master the CRUD function are granted in the detail table.

tabulator: accountID

The accountID is set to "visible":false.

k8form: accountID

The accountID is set to "type":"hidden".