Many-to-many Relations

Many-to-many Relations

The SaveToDB add-in has a special mode for editing data in many-to-many relations.

Consider three tables: employees, territories, and employee_territories.

The employee_territories table contains two foreign key columns: employee_id and territory_id.

When you retrieve data from the employee_territories table without any filters applied on the ribbon, you get the following data:

employee_idterritory_id_State_
Employee 1Territory 1
Employee 1Territory 2
Employee 2Territory 3

The add-in adds the checkbox _State_ column, which you can use to add or remove relations.

You can create a pivot table using the Excel data table as a data source. Place the foreign key columns on the axes and the SUM of the _State_ column in the cells. You’ll see a table like this:

Territory 1Territory 2Territory 3
Employee 1
Employee 2
Employee 3

The add-in also adds validation lists for foreign key columns as axis items.

You can double-click in the pivot table to modify the underlying table's data and save changes directly from the pivot worksheet!

Returning to the table, you can select a value on the ribbon. For example, if you select Territory 1, the table will look like this:

employee_idterritory_id_State_
Employee 1Territory 1
Employee 2Territory 1x
Employee 3Territory 1x

You can double-click on the _State_ column value to add or remove the relation.

If you select Employee 1, the table will appear as follows:

employee_idterritory_id_State_
Employee 1Territory 1
Employee 1Territory 2
Employee 1Territory 3x

To implement these features, the add-in automatically configures itself by reading the database metadata:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s07employee_territoriesemployee_idValidationLists07employeesTABLE[employee_id],[last_name]
 s07employee_territoriesterritory_idValidationLists07territoriesTABLE[territory_id],[territory_description]
 s07employee_territoriesemployee_idManyToManyATTRIBUTE
 s07employee_territoriesterritory_idManyToManyATTRIBUTE
 s07employee_territoriesAddStateColumnATTRIBUTE

The add-in uses the ManyToMany event type for foreign key columns and the AddStateColumn event type to add the _State_ column. It also creates validation lists based on the primary key tables.

You can create similar configurations for other objects, such as loading data from stored procedures or views.

If you want to disable automatic configurations, use the DoNotAddManyToMany event type in the xls.handlers table.

This website is using cookies. By continuing to browse, you give us your consent to our use of cookies as explained in our Cookie Policy.