Most apps will need more than one object. When this is the case, these objects will likely be related or connected to one another.
You can define these connections in Knack so that records from one object can be connected to records in another object.
Each object’s connections are listed in the right column:
The easiest way to add a connection is to click the "Add connection" link from the right column. This will present a new window where you first select the object you want to connect to:
You then describe how that connection will work:
When you add a new connection, it creates a special connection field in that object:
These fields can be used like any other field throughout your app. If you add a connection field to a form, it will operate like a lookup, so you can select a specific record from the connected object to connect to.
Which Object to Add Your Connection to
You only need to add one connection field to create a connection between two objects, so which object should you add that field to?
The good news is that ultimately it doesn't matter; Knack will be able to work with the connection regardless of which object you add it to. With that said, there are a few rules of thumb that can help you decide.
In a one-to-many relationship, it generally works best to add the connection to the object with **many** connections. Or to put it another way, in a parent-child relationship, it works best to add the connection to the child object.
For example, in our Job Listings example app, one job can connect with many applications, so it will work best to add the connection to the Application object. This way, when we're editing or viewing an application, we can easily see which Job it’s connected to.
Here's what a connection will look like in a form when it's added to the Application (the child object):
In this example, the application is connected to the "Executive Assistant" job. You can change which job it is connected to with the drop-down.
Here's what it would look like if it was added to the Job (the parent object). Instead of connecting to one record it would need to connect to all the applications:
This can be a little slower and might take a while to download the full list of applications. In this example, the job is only connected to two records ("Richard Knowlton" and "Jane Maurice"), but if there were hundreds of applications, this could get cumbersome.
Another reason the child object generally works best is that you'll typically create the parent records first. So when adding a child record, you'll have some parent records already created that you can connect to.
For many to many connections, you generally want to add the connection to whichever object you'll be editing in the interface with a form view to manage those connections.
Click on a connection field if you need to change how the connection works:
Note that changing a connection can affect your live application! If you've added views using that connection and then change it, those views may not work correctly.
Connections and Records
Once your connection fields are added, you can edit these fields in your records just like any other field. Here's an example of updating the company that a contact is connected to:
When editing a connection field, you're able to choose from all the records from the connected object.
Those records are identified by a single field. This will default to the first field added for that object (in the example above, the Company Name).
You can change this field by updating the display field for that object. Select the object, go to the "Settings" tab and then the “Display Field” setting: