How to Create an Association Between Tables in Custom Data?
An association between tables allows selecting data from one table in another. This is useful when you need to create a relationship between different entities (for example, tasks and priorities, products and categories).
When Needed
- You need to select values from one table when creating a record in another.
- You need to create a "one-to-many" relationship between tables.
- You need to organize structured data with links between tables.
What's Important to Know
- Association — field type that allows creating links between different data models.
- Association type "one-to-many" means that one record from one table can be linked to many records in another.
- When editing a record, values from the associated table will be available in the dropdown list.
- The field that will be displayed after the association is selected from the associated model.
Prerequisites
You are logged in with integrator or administrator rights. There are two created Custom Data models in the system (the one in which the association is created, and the one from which data is taken). You have navigated to the Custom Datamodule viaApps -> Custom Data.
Step-by-Step Instructions
- In the
Custom Datamodule, go to the "Create/Update" tab. - Open the model in which you need to make a selection from another table (for example, "Tasks").
- Add a new field or edit an existing one.
- Select field type "Association" (ASSOCIATION).
- Configure association parameters:
- Association Type — select "one-to-many"
- Model to take data from — select the model from the list (for example, "Priorities")
- Field to display — select a field from the associated model that will be shown in the dropdown list (for example, "priority_name")
- Save changes in the model.
Usage Example
If you have a "Priorities" table with fields "priority_id" and "priority_name", and in the "Tasks" table you need to select a priority:
- Open the "Tasks" model.
- Add an "Association" type field.
- Configure:
- Model: "Priorities"
- Field for display: "priority_name"
- Save the model.
After this, when editing a record in the "Tasks" table, values from the "Priorities" table will be available in the dropdown list (for example, "High", "Medium", "Low").
What Happens After
After creating the association, the "Association" type field is displayed in the model. When creating or editing a record, values from the associated table will be available in the dropdown list. The selected value is saved as a link to the record in the associated table.
How to Verify It Worked
- Check that the "Association" type field is added to the model.
- Make sure the correct model and field for display are selected.
- Create a test record and check that values from the associated table are displayed in the dropdown list.
- Check that the selected value is saved correctly.