Links
Comment on page

Many-to-many relationships

A many-to-many relationship describes the case where multiple records in one object class are related to multiple objects in another object class. This guide describes how to create many-to-many relationships in Appfarm Create.
For a guide to implementing UI functionality for many-to-many relationships see how to represent a many-to-many relationship.

Example of a many-to-many relationship

Say you have an object class Employee to store all your organization's employees and an object class Skill to store all the skills relevant to your organization. You would like to be able to track which employees have which skills.
Since an employee can have multiple skills and a skill can be held by multiple employees you need to create a many-to-many relationship to be able to track this information.

Create a many-to-many relationship

In Appfarm Create you create a many-to-many relationship by adding a new object class that contains references to the two object classes to be related. This is similar to a junction table in traditional relational databases.
Continuing the example above, you'd create a new object class Employee Skill with two properties: Employee, with a reference to the Employee object class, and Skill with a reference to the Skill object class.
An example of a many-to-many relationship as shown in the data model designer.
The steps below assume that you have already created the individual object classes (for example, Employee and Skill) that are to be related.

Step 1

Add a new object class to your data model. Best practice is to name this object class using a combination of the names of the two object classes to be related, for example Employee Skill.

Step 2

Add a new property to the newly created object class. This property will store references to another object class that represents one half of the relationship.
  • Property Name: Best practice is to use the name of the object class, for example Employee.
  • Data Type: Select the object class to relate under References, for example Employee.

Step 3

Add another new property to the object class. This property will store references to another object class that represents the other half of the relationship.
  • Property Name: Best practice is to use the name of the object class, for example Skill.
  • Data Type: Select the object class to relate under References, for example Skill.
Now you have an object class that references two other object classes. Each record added to the object class represents one connection between the two object classes. For example, an individual employee and one skill that they possess. Each employee will have a unique record for each skill they possess and each skill will be represented based on how many employees possess that skill.
Note that to use these object classes in an app or service you need to add data sources.
Appfarm is currently exploring a concept to allow a single object class property to hold a list of object class references. With this concept, the need to create object classes to store many-to-many relationships may be removed.