Connection Types

In this article, we will explore how the connection type you choose depends on how your data works together in your Knack app.

This article covers the following topics:

 

Overview

There are three types of relationships that can be established using connections: one-to-one, one-to-many, and many-to-many.

In this article, we will explore how the connection type you choose depends on how your data works together. Here are some common examples using the connection types:

  • One "Manager" record connected to one "Location" record

  • Many "Contact" records connected to one "Company" record

  • Many "Student" records connected to many "Class" records

To learn more about using connections in general, you can learn more in the following articles:


 

One-to-One Connections

This connection type ensures that each record is exclusively associated with a single record from the connected table, and vice versa.

As an example, consider a business that operates multiple warehouse locations, with a specific manager assigned to each location. In this particular scenario, we have two tables: the Manager table (or user role) and the Locations table.

In a connection between the Manager table and the Location table, each manager record is linked to a corresponding location record, and each location record is associated with a manager record.

connection types

Note: While the relationship between these tables is 1:1, we are not actually enforcing that the connected record can only be used once.

 

Where to Add the Connection

To establish a one-to-one connection, it is recommended to add the connection to the table that you will be regularly working with.

For example, if you wish to assign a manager to each location from the location page, you should add the connection to the location table. This will display as a connection field on the Locations table, allowing you to select a manager to assign to the location.

 

 

One-to-Many Connections

This connection type allows multiple records from one table to connect to a single record from the connected table.

For instance, in a corporate contact directory, each company can have several contacts associated with it. This type of connection is known as a one-to-many connection:

connectiontypes3

 

In a connection between the Contact table and the Company table, each contact record is linked to one company record, and each company record is associated with multiple contact records.

connectiontypes2

By establishing a one-to-many connection, you gain the ability to create a page for your Live App that showcases a particular company and conveniently lists all of its associated contacts below. When you add a new contact from the company's dedicated page, you can configure your form so that the newly added contact is automatically linked to the company on that page.

Where to Add the Connection

When working with a one-to-many relationship, you have a parent and a child table. The parent table is the “one” part of the relationship, and the child table is the “many”.  

In this example, Companies is the parent table, and Contacts is the child table.

In a one-to-many connection, it is recommended to add the connection to the child table. This approach enhances workflow options, improves visual presentation, and streamlines data management within your applications.

 

 

Many-to-Many Connections

This connection type allows each record in one table to establish connections with multiple records in the connected table, and vice versa.

As an example, consider a relationship between a table of Students and a table of Classes, where each student record is associated with multiple class records, and each class record is linked to multiple student records.

connectiontypesthree

Where to Add the Connection

With a many-to-many connection, add the connection to the table you will be editing more often.

If you have multiple students assigned to multiple classes, consider which one you would like to edit in order to establish connections between the records.

Would you like to add classes to each student from the student's record? If that's the case, it would be best to add your connection to the Student table.

connectiontypes6