In a restdb.io database, you can create two types of relations between collections: lookups and parent-child.
This page shows how you can create lookup relations between two collections.
A "lookup" in restdb.io is a kind of one-to-one or one-to-many relation.
They are ideal to use when there are one or a few data items that need to be associated between two collections. A lookup relation allows multiple records to reference the same record(s) (unlike parent-child). Also, when you have a big number of data items, we recommend using a parent-child relation. This is due to the fact that lookup id's are embedded directly on a record (see below for details about the JSON storage format).
Lookup relations are added in the same way as fields. In Developer Mode, on the collection view, you click the Add Field+ button. In the slide-in dialog that shows up, you scroll down to the section Relations to Collections and select a collection. Here we'll select Company.
The lookup relations are the select one (collection name) and the select many (collection name). For this example, we choose "select one company" as shown below.
Lookups are similar to HTML selects. In restdb.io they are made mobile friendly and slides in from the right. The selection list has a search filter and you can also create a new record in the collection the lookup links to (here: Company).
When you click on a lookup link on a record, you navigate directly to the record. A convenient feature is that when you visit a record being linked to by another, you'll see a tab for each lookup relation it takes part in. Here we see the tab Contact which links to this Company. Clicking on the tab will reveal a list of records (only one in this case).
A lookup is stored as an embedded object on the record. This is convenient and saves extra REST API calls to get the company record details. To see the JSON of a document, simply click the JSON data view button as shown here:
Please note that a lookup is always stored as an array, even if it's a select-one relation