How To: One-to-Many Relationship
Parent-Child Relationship
Handling one-to-many relation scenarios is very easy within WaveMaker. Going with the example of sample database, we will see how to display Employee details for a selected Department.
Drag and drop a Data Table
- CREATE NEW Variable with hrdb as service and Department as the Operation/Type
2. Select any **layout** of your choice, here we have selected _Read-only_
[![dt1_dept_layout](/learn/assets/dt1_dept_layout.png)](/learn/assets/dt1_dept_layout.png)
3. Select the **Name**, **Deptid** and **Budget**
[![dt1_dept_fields](/learn/assets/dt1_dept_fields.png)](/learn/assets/dt1_dept_fields.png)
- Drag and drop another Data Table onto the canvas
- CREATE NEW Variable with hrdb as service and Employee as the Operation/Type
- Select any layout of your choice, here we have selected Read-only
- Select the Firstname, Lastname and Picurl. Set the Widget to Image for Picurl column.
- From the canvas, select the second grid and open the hrdbemployee variable. From the Data tab, set the Filter Field on department to the deptid field of the selecteditem of the first grid
- Run the app, click on a department and see the table with employee details displayed
We will extend the previous related tables use-case, to have an editable employee details. Going with the example of sample database, we will see how to display Employee details for a selected Department and add/update the Employee details.
Drag and drop a Data Table
- CREATE NEW Variable with hrdb as service and Department as the Operation/Type.
- Select any layout of your choice, here we have selected Read-only.
- Select the Name, Deptid and Budget.
Drag and drop another Data Table onto the canvas.
- CREATE NEW Variable with hrdb as service and Employee as the Operation/Type.
- Select any layout of your choice, here we have selected Editable with Form as Dialog.
- Select the Firstname, Lastname and Picurl. Set the Widget to Image for Picurl column.
Select a layout and fields for Live Form. We have selected a 2-column layout with all fields displayed.
From the canvas, select the second grid and open the hrdbemployee variable. From the Data tab, set the Filter Field on department to the deptid field of the selecteditem of the first grid.
Select the department field of the form, for this use the widget tree on the left Files Panel.
- bind the default value to the selecteditem of first grid
- bind the dataset value to hrdbEmployee variable
- set data fields to all fields and display field to name
- Run the app, click on a department and see the table with employee details displayed
- Click ADD to add a new row, a form dialog will be displayed. Note that the Department is set to the selected department.