Recursivity
This section assumes a good understanding of subitems.
When the items of a collection can themselves point to other items of that same collection, we describe that relation as being recursive. Such relation can describe an infinite loop of interconnected items,each pointing to one another.
Let's imagine our Pokémons can have friends. And those friends can themselves have friends, and so on. Trying to represent these friends as subitems without recursivity would force us to describe an infinite level of deeply nested relation summaries, each time repeating the exact same schema.
{
relations: [
{
name: "pokemons",
label: "Pokémons",
path: "/pokemons",
schema: {
label: "Pokémon",
fields: [
{
name: "name",
label: "Name",
type: FieldValueType.STRING,
}
],
relations: [
{
name: "friends",
label: "Friends",
schema: {
label: "Friend",
fields: [
{
name: "name",
label: "Name",
type: FieldValueType.STRING,
}
],
relations: [
// repeat the same thing, again, indefinitely
]
}
}
]
}
}
]
}
It's possible to avoid such a pattern by using the special __self
keyword. When used in place of a relation summary's
schema, it indicates that the schema is the same as the one of the relation it belongs to.
Rewriting our example above with this keyword greatly simplifies everything.
{
relations: [
{
name: "pokemons",
label: "Pokémons",
path: "/pokemons",
schema: {
label: "Pokémon",
fields: [
{
name: "name",
label: "Name",
type: FieldValueType.STRING,
}
],
relations: [
{
name: "friends",
label: "Friends",
schema: "__self"
}
]
}
}
]
}
For more information on recursivity, please visit the recursivity documentation.