What's a Connection?
Most apps will need more than one object. When this is the case, these objects will likely be related or connected to each other.
Here are some examples of possible connections:
Many contacts can be connected to one company
One order can be connected to many products
Many managers can be connected to many projects
Knack defines these relationships with connections. Adding a connection means that records from one object can be connected to records from another object. These connections can be used throughout your app to add powerful functionality.
In the contact directory example app, we have two objects: Companies and Contacts. Each contact record is connected to a company record.
This means we can view a company and add a view to show all the contact records connected to that company.
The same app also has a Notes object, where each note is connected to a contact. This enables us to show notes connected to each contact.
Knack uses a special connection field to define the relationship between two objects.
Each object has a special area in the right column that lists any connections it has:
You can use the "Add connection" link in that column as a shortcut to add a new connection:
Connecting Records Together
Once you've defined your connections, you can connect your records together.
Connection fields work like lookups, so when you edit a record, you can use that field to "look up" which record(s) to connect it to. Here's an example of connecting a specific contact to a company record:
Each company record will be available in that drop-down to connect the contact to.
The company records are displayed in that drop-down with a single field: the display field. In this case, it's the Company Name field. You can change which field is used to identify the records in the "Settings" link at the top:
You can also define connections when importing new records. If you are importing some employee records, you could connect each employee to a company by using a column like "Company Name" to match against a company record and connect to.
Once your records are connected, you can use these connections in powerful ways throughout your application.
Display Connected Records in Your Live App
One of the best ways to use connections is to show connected records in your live app. For example, we could show any contacts connected to a single company:
When you add a view on any details page, you'll see options for displaying these connected records:
Click here for more on displaying connected records.
Add Connected Records with Forms
Similar to the example above, you can also add a form view to add a connected record. When you add a new record with a form, that connection is automatically set based on the parent record being viewed.
Combine Connected Records in Views
When you display records in a view (such as a table or list), you can include fields from other connected records.
Any connected objects will be listed above the current fields in a drop-down list. Click the small drop-down arrow to open that list and select another object:
In the example above, you could include fields from the company each contact is connected to.
Use Dynamic Dropdowns in Forms
You can use connections to two objects to set up dynamic drop-down lists, like having a country selection automatically update the list of available cities connected to that country:
When you have both connections on your form, you can set the second connection to use the first. Hover over the connection input in the form and click the edit "pencil" icon:
Calculate Sums, Averages, and Formulas on Connected Records
Formula fields are special fields that run calculations on connected records and stores the result.
For example, you could store the count of students connected to a class, or the average sale connected to an employee.
Click here for more on formula fields.
Include Connected Values in Equations
Equation fields let you include values from connected records:
Click here for more on equations.
Display Records Connected to the Logged-in User
When you connect objects to user roles, you can add views to show those records connected to the logged-in user. When you add a view, you'll see these options:
In the example above, you add views to display Tasks connected to the logged-in Employee.
Click here for more on showing records connected to the logged-in user.
Display Reports Grouped by Connections
Connections can be used to group reports. The report will run calculations on the different groups of connected records.
Click here for more on reports.
Link to connected views
When displaying a connection field in a view, you can display those values as links to view more details about each connected record. In order to add these links, a page capable of displaying details of that record will need to exist. Click on the connection field when editing the view to update the following:
- Determines how each value in the connection field will display. Options include Comma-separated, or New Line.
- Allows you to choose an existing page for the object the connection links to. Adding a link will make each value its own separate link to view more information about that record.
In the following example, the Company column has the Value Link set to a company details page so each company can be clicked to view more details: