Dittofi
  • Tutorials
    • Tutorial Index
    • Quick Start
    • Dittofi Essentials
      • Part 1: Frontend terms and concepts
      • Part 2: Backend terms and concepts
      • Part 3: Connecting frontend and backend
      • Part 4: Dittofi app structure
    • Dittofi App Design
      • 🏗️App architecture 101
      • ◼️Backend app development 101
      • 🟪Frontend app development 101
      • 🔰(optional) Web developer beginner series
  • Learn Frontend
    • 👨‍💻Getting Started
      • Welcome to Dittofi
      • Intro to the Dittofi Design Studio (Frontend)
    • 🟩Pages
    • 🟪Elements
      • Types
        • Button Element
        • Div Block Element
        • Form Block Element
        • Link Block Element
        • List Element
        • Modal Box Element
        • Tabs Element
        • Columns Element
        • Image Element
      • Partials
      • Prefabs
      • Custom
    • 🟧Variables
      • Array
      • Checkbox
      • Collection
      • Collection (Custom Model)
      • Collection (System Custom Model)
      • Custom Model
      • Date
      • Datetime
      • File
      • Json
      • Number
      • Number with decimal
      • Model
      • System Custom Model
      • Text
      • UUID
    • 🟨Events
      • 🟨External
        • HTTP Request
        • Run Endpoint
      • 🟨Flow Control
        • Condition
        • Run Action
        • Loop
        • Sleep
      • 🟨Maths
        • Add
        • Divide
        • Modulus
        • Multiply
        • Subtract
      • 🟨Navigation
        • Open Page
      • 🟨Notifications
        • Alert
        • Confirm
      • 🟨Other
        • Copy To Clipboard
        • Run Custom
      • 🟨Text
        • Concat
        • Contains
        • Ends With
        • I Contains
        • I Ends With
        • I Starts With
        • LTrim
        • RTrim
        • Text To Upper
        • Text To Lower
        • Trim
        • Starts With
      • 🟨Variables
        • Set Field
        • Remove Field
      • Validate
    • 🟦CSS Layouts
      • Holy Grail Layout
      • Side Bar Layout
      • Sticky Footer Layout
      • Sticky Header Layout
      • CSS Frameworks
    • 🔲CSS Frameworks
    • Component Libraries
    • Meta Attributes
  • Learn Backend
    • 🖥️Getting Started
      • Intro to Data
      • Intro to APIs
      • Build your first custom API
      • Actions & Events
    • 🟫Back-End Actions
    • 🟩Custom Models
      • 🟩Attributes
        • Array
        • Checkbox
        • Custom Model
        • Collection (Custom Model)
        • Collection (System Custom Model)
        • Date
        • Datetime
        • File
        • Number
        • Number With Decimal
        • Json
        • Text
    • ◼️Data Models
      • Database Fundamentals
        • Database relationships
      • ◼️Columns
        • Attachment
        • Auto Increment
        • Checkbox
        • Date
        • Datetime
        • Duration
        • Email
        • Long text
        • Link to another record field
        • Number
        • Number with decimal
        • Password
        • Phone number
        • Percent
        • Price
        • Rating
        • Single select
        • Single line text
        • URL
    • 🟥Events
      • 🟦Arrays
        • Append
        • Array Pop
        • At
        • Length
        • Prepend
        • Range
      • 🟦Conversions
        • Base64 Encode
        • Base64 Decode
        • Json Decode
        • Json Encode
        • Path Escape
        • Path Unescape
        • Query Escape
        • Query String Parse
        • Query Unescape
        • To Bool
        • To Float
        • To Int
        • To Str
        • Yaml Encode
        • Yaml Decode
      • 🟦Database Requests
        • Create
        • Create Or Update
        • Delete
        • Has Record
        • Read Event
        • Update
      • 🟦External
        • HTTP Request
        • SFTP Download
        • SFTP Upload
      • 🟦Files
        • CSV Reader Event
        • CSV Writer Event
        • File Read
        • File Save
        • File Size
        • File Type
        • JSON Reader
        • PDF Generator
      • 🟦Flow Control
        • Condition
        • Loop
        • Return
        • Run Action
        • Sleep
      • 🟦Notifications
        • Send Mail
        • Connect Websocket
        • Message Websocket
      • 🟦Maths
        • Add
        • Acos
        • Acosh
        • Asin
        • Asinh
        • Atan
        • Atanh
        • Cbrt
        • Ceil
        • Divide
        • Modulus
        • Multiply
        • Subtract
      • 🟦Security
        • Compare Password
        • JWT Decode
        • JWT Encode
        • Login
        • Logout Web User
        • Password Generator
        • Random Number
      • 🟦Time
        • Add Time
        • Day
        • Format Time
        • Minute
        • Nanosecond
        • Parse Time
        • Second
        • Time In
        • Year
        • Year Day
      • 🟦Text
        • Concat
        • Contains
        • Ends With
        • Execute Template
        • I Contains
        • I Ends With
        • I Starts With
        • Starts With
        • LTrim
        • RTrim
        • Replace
        • Regex Find All String
        • Regex Find String
        • Regex Match String
        • Trim
        • Text To Lower
        • Text To Upper
        • Text To Title
        • Url Getarg
      • 🟦Other
        • Assign
        • Run Custom
        • Redirect Web Page Event
        • Render Web Template Event
    • 🟧Variables
      • Array
      • Checkbox
      • Collection
      • Collection (Custom Model)
      • Collection (System Custom Model)
      • Custom Model
      • Date
      • Datetime
      • File
      • Json
      • Number
      • Number with decimal
      • Model
      • System Custom Model
      • Text
      • UUID
    • 🟪Webservices
  • Templates
    • Two sided marketplace template
      • Introduction
        • Part I: Installing and setting up the marketplace template
        • Part II: Understanding what features are included in the marketplace template
        • Part III: Customizing your marketplace frontend without coding
        • Exploring Dittofi's marketplace API
      • Listings
        • How to create a marketplace listing
    • How to build a CRUD app
  • Third Party APIs
    • OAuth 2.0 APIs
      • Introduction To OAuth 2.0
      • Google OAuth 2.0 - PART I
      • Google OAuth 2.0 - PART II
  • Dittofi Admin
    • Your Account
      • Workspace Admin
      • Manage Billing
      • Connect a custom domain
      • How to use a discount code to Dittofi Pro
  • FAQ
    • API Generator
    • How to write custom SQL?
    • Why does my image not display?
    • How can I set up Google Analytics?
    • Exporting and deploying my frontend code
    • What is a partial and what is a prefab?
    • How to set up a basic mulit tenant app on Dittofi
    • How to write a custom endpoint in Dittofi
    • How to integrate Font Awesome into Dittofi
    • How can I set up Dittofi to run on my own private server?
    • How to add roles such as Super Admin, Admin, Manager & User
    • How to prevent duplicate records being added to the database
    • What to do when relation cannot be created because their is violating data in the referenced table
  • Change Logs
    • Dittofi Change Logs
Powered by GitBook
On this page
  • Defining relationships
  • Creating relationships
  • Using relationships
  • Entity relational diagram

Was this helpful?

  1. Learn Backend
  2. Data Models
  3. Columns

Link to another record field

PreviousLong textNextNumber

Last updated 3 years ago

Was this helpful?

When developing an application, you will end up with lots of data stored inside your data models. Whenever you want to perform an action on an existing record or create a new record, you will want to not only perform an action on one record in one table, but also to perform that same action on any connected records. In this lesson we will cover how you can use Dittofi's "Link to another record" field type to help manage your apps data in the best possible way.

We will cover:

  • Defining relationships

  • Creating relationships

  • Using relationships

  • Entity relationship diagram

Defining relationships

Before you start building relationships, you want to have a plan for your data and how your relationships are going to look. Essentially you want to think about what data your app is going to store and how that data connects together.

The data that you want to store and how you want to connect it together is completely dependent on what you're trying to do. For example, you might have a table of users and a table of user identification documents or alternatively you could have a table of property owners and a table of properties which are owned by each one property owner.

When building your app, it is best practice to keep this data in different tables to avoid any duplication of data. But, just because the data is stored in separate tables, this does not mean that it should live in isolation.

Your users will have related identification documents, your property owners will have related properties and so on.

Notice, in the example above that Owner 2 owns two properties (Property 1 and Property 3). You can see this by looking at either the Property Owners table or the Properties Table.

Before you go on, think about the data that your app is going to need e.g. users, products, drivers etc.

Next you can try asking yourselves questions similar to:

  • Does each product have many orders?

  • Does each property have many owners?

  • Does each driver have many trucks?

  • ETC...

Asking these questions of your specific data will allow you to start to understand what relationships exist between different types of data.

Creating relationships

There are two main ways that we can create relationships between different tables:

  • Using the Link to another record field (for common relationships)

  • Using the object relational diagram (for more complex relationships)

In this section we are going to cover using the Link to another record field.

The first step to creating the relationships between two tables is to create the two individual tables. In our example, let's build two tables, a Property Owners table and a Properties table.

Next, let's add add a column to our Property Owners table called "Link to properties table" and make it of type Link to another record.

Next, we pick the table that we want to link our Property Owners table to. In our case this is our Properties table and choose the type of relationship between the tables.

Note, when we choose how we want want to link the tables together, there are three different options:

In our case, one property owner can have own many properties, so we select the option One "Property Owners" record has many "Properties" records.

Once we have created the relationship, we can start linking individual records by using the "+" button that is visible inside our new field in the Property Owners table. Clicking this "+" brings up a popup with different numbers in it. These numbers correspond to the unique ID's of the records in our "Properties" table.

Note, anytime that a relationship is created, you will notice that a corresponding link appears in the linked table.

--> Now it's your turn. Go ahead and create your linked records. First, create the linked record field and use this to create the relationships that you mapped out in the last section. Once you have added the linked record field, you can link the relevant records together from your two tables.

Using relationships

Example of a Get property_owners Endpoint below.

Running the API Generator for the Properties table, you can generate the same set of endpoints for the linked data. You can see an example of the Get properties Endpoint.

Entity relational diagram

The entity relationship diagram, also known as an ERD, is a diagram that can be used to visualize the relationships between different tables. The diagram is often used in database design to map out the relationships and provides a good means of communication. Below is an example of the relationships we have built between our Property Owners and Properties table.

You are able to visulize your tables using the entity relationship diagram inside Dittofi by clicking on the TABLE RELATIONS button inside the Data Models tab.

Note, the relationships built using the Link to another record property type are not visible here. This is because this data type is creating links in an alternative, more user friendly way. If you want to build a relationship within this view, you need to (A) click on the table that you want to link to a parent table from within the entity relationship diagram view, (B) select "Relations", (C) click "+Add Relations" and (D) select the parent model and fields to link on.

The easiest way to use your relationship within your app development is to run the for the tables where you have created the relationship. This will allow you to auto generate code to for example, fetch the data from your data model and display it in your frontend.

Note, you will need to run the API Generator for both of your tables. If you want to have only one set of endpoints, you can set up a to collect the data from the joined up tables.

◼️
◼️
API Generator
custom query
Property owners and their properties.
Note, two way linking
Linking property owners and properties