Many-to-many relationships
Last updated
Was this helpful?
Last updated
Was this helpful?
A many-to-many relationship describes the case where multiple records in one are related to multiple objects in another object class.
A Person has many Skills, and each Skill has many Persons.
A Project has many Project members (Persons), and each Person is a member of many Projects.
Appfarm supports multi-references, i.e. with Cardinality Many, to hold a list of references towards an Object Class or Enumerated Types. This is a great option if you only need information about references. For example: Person.Skills
may be a multi-reference towards the Skill
object class, if you only need to know the list of skills for a person (and which persons that have a certain skill) - and you do not need to know e.g. which level a person has.
Note that you may also define multi-reference properties as on data sources, or .
This guide describes how to create many-to-many relationships in Appfarm Create.
Say you have an object class Person
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 (but not which level).
Since a Person
can have multiple Skills
, and the Skills
are considered to be information related to the Person
(and not Persons being information related to Skills), we need the following:
A Person
object class
A Skill
object class
A property Person.Skills
, with a reference towards the Skill
object class, with Cardinality Many
.
Person.Skills
may contain a list of Skill ID
s, and in general you may treat this property as a Data Source with Cardinality Many. Here are some key features:
However, if you need to store information about what level each Person has for each Skill, you may not use the above approach. See the following example.
Given the above example: We now want to save information about what Skill Level each Person has for each Skill.
In that case, we need the following:
A Person
object class
A Skill
object class
An enumerated type Skill level
A Person Skills
object class
Person Skills
is a many-to-many relationship object class that contains references to the two object classes to be related: Person and Skills. In addition, it has a reference to the enum Skill level. For each Person's skill, a record should be created into this Object Class (holding the ID of the Person and Skill, and the Value of the Skull level enum).
To create the Person Skills
object class:
Property Name: Best practice is to use the name of the object class, for example Person
.
Data Type: Select the object class to relate under References, in this case Person
.
Cardinality: One.
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, in this case Skill
.
Cardinality: One.
Add another new property to the enumerated type Skill level.
Property Name: Best practice is to use the name of the object class, for example, Skill level
or just Level
Data Type: Select the enumerated type to relate under Enums, in this case Skill level
.
Cardinality: One.
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 person and one skill that they possess, and the level. 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.
Person.Skills
can be set in a or an action node, or directly in the UI using a (with selection type Property)
You may add or remove IDs to/from Person.Skills
using Update Object and a value processor, as in .
You may iterate Person.Skills
in a Action Node or an or in your UI.
You may use Filter and Conditions towards Person.Skills as if it was a multi-cardinality data source. Note that the wording is slightly different (Has Some Of / Has None Of instead of Exists In / Not Exists In). You may read more on this example in the .
Add a to your data model. The best practice is to name this object class using a combination of the names of the two object classes to be related, for example Person Skill
.
Add a to the newly created object class. This property will store references to another object class that represents one half of the relationship.
Note that to use these object classes in an app or service you need to add .