# Many-to-many relationship between tables

[Application configuration](application_configuration.md) > [Data model editor](data_model_editor.md) > Many-to-many relationship between tables

Tables in a data model are often related in a way that defines one table as parent, and another as child, where one record of the first one can have a relation with many records of the second table, for instance, an _Invoice_ having many Items, or many _Service orders_ requested by a _Customer_ (i.e., a one-to-many or many-to-one relationships). But there are business cases where it’s necessary to establish a many-to-many relationship where the records of the tables can be related both ways, for example, in a school a _Teacher_ has many students, and a single _Student_ has many teachers. In a company a _Manager_ is responsible for many _employees_, and a single _Employee_ may be reporting to more than one _manager_.

IS Tools makes it possible to have a many-to-many relationship via a junction table that will link the two tables in consideration. To implement this, follow the steps below:

1.  In [Data model editor](data_model_editor.md), create the two tables that you wish to see in forms in a many-to-many relationship. Based on the example above, create "Teacher" and "Student", with some fields.

2.  Create a third table with:

    -   two Relation fields, one for each table above (no more fields than these two are recommended for many-to-many, instead it is a feature for [one-to-many](one_to_many_relationship.md)),

    -   a [Default record group](tables.md#Default_record_group), and

    -   Record name as [Generated series](tables.md#Generated_series).  

        You may call it "Linking table" with relation to "Teacher" and "Student".  

        ![Many to many](_images/Many-to-many.png)

3.  Save the changes.

4.  In [Form designer](form_designer.md), create a form, and:

    -   select the first table above and drag and drop it to create a Detail section\*. For instance, a form called "Teachers". If you like, add some fields created in step 1.

    -   Note that this table shows a _reverse relation_ field (![Reverse relation](_images/Reverse_relation.png)), e.g., "Teacher Linking table → Student". Select it so an additional "Fields" panel in **Data model editor** is displayed, where a _forward relation_ (from the linking table to "Student") can be found. Drag and drop it onto the Detail section. A [Multi value](field_types.md#Multi-value) is added to the form section.  

        ![Multi input value field](_images/Multi-input_value_field.png)

5.  Save this form and create a new one for the second table created in step 1, also adding the corresponding Multi value. For example, this form can be called "Students". Save it.

6.  Open the generated forms and create records, e.g., . For instance, "John Smith" and "Aurora McArthur" for the "Teachers" form, and "Jimmy", "Charly" and "Laura" for "Students".

7.  Once the records are saved, use the Multi value to relate multiple records from both tables.  

    ![Many to many in Detail section](_images/Many-to-many_in_Detail_section.png)

> **Tip:**
> 
> Note that the Multi value can be resized so related records can be seen for instance in a vertical way, or much wider to show more records.

> **Tip:**
> 
> You can also consider configuring the form in step 4, adding the Linking table as a Table section instead of the Multi value. However, note that no access rights will be checked on the linking records, i.e., this is a special table that is not bounded to rights like regular tables do in the system.
> 
> ![Many to many with Linking table](_images/Many-to-many_with_Linking_table.png)

\*Multi detail and Table sections can also be used for this purpose.
