Hi, folks!
Hope, this workaround would be helpful for someone. If you have any questions or suggestions - feel free, to share them here, in comments
Problem
There are two Databases you would like to connect via [automatic linking]
(Automatically Link entities | Fibery Help Center). However, a simple mapping is not enough since one of the linking rules involves a to-many relation:
In this example we are trying to connect Conferences and Segments via their Region and Industry Cluster:
A Conference has many Industry Clusters and this makes things difficult.
Solution
We need to replace =
âequalâ in the rule with something like â
âis an element ofâ: ```
Link Conferences to Segments if
- they have the same Regions
- Segmentâs Cluster is an element of Conferenceâs Clusters collection
While we donât have â
available, we have the next best thing â contains
. Itâs not available on UI, but we can configure such a rule via the API. This is how, for example, Commits get linked to Pull Requests in our Github integration.
Step-by-step guide
The Database that has a to-one relation participating in the auto-linking rules:
( Segment)
- Create a Formula Field to extract the relationâs ID:
"{" + [Industry Cluster].[Public Id] + "}"
The Database with a to-many relation
( Conference with its collection of Clusters)
- Since
contains
works with text, we need to transform the collection into text. So we add an auxiliary Formula to extract IDs:[Industry Clusters].Join("{" + [Public Id] + "}",",")
.
- Create a relation Field to the other Database.
(from Conference to Segment in our case) - Enable auto-linking and set it up as if all relations are to-one:
- Add
?dev
to the end of your URL
https://YOUR_WORKSPACE.fibery.io/fibery/space/YOUR_SPACE/database/YOUR_DATABASE?dev
- Open the browser console.
- Copy the existing auto-linking rules configuration (make sure to replace Space and DB names with yours):
dev.schema.typeObjectsByName["Market Test/Conference"].fieldObjectsByName["Market Test/Segments"].rawMeta["link-rule/link-rule"]
- Replace
=
withq/contains
and execute the command from the console:
await dev.api.executeCommandsAllOrNothing({commands: [
{
"command": "fibery.schema/batch",
"args": {
"commands": [
{
"command": "schema.field/set-meta",
"args": {
"holder-type": "Market Test/Conferences",
"name": "Market Test/Segments",
"key": "link-rule/link-rule",
"value": {
"logicalOperator": "and",
"operands": [
{
"expression": [
"8cc865f6-714d-4cba-b6da-f5e2c1e0f96b",
"15dd709e-3733-4d8c-bbf4-9de8a0b16a43"
],
"relationExpression": [
"682b92f8-584f-4c5b-b5b1-45ac23b5069c",
"15dd709e-3733-4d8c-bbf4-9de8a0b16a43"
],
"operator": "="
},
{
"expression": [
"0812db29-d32e-4f41-9295-7b0c21ae662f"
],
"relationExpression": [
"98cb3527-17d9-4870-b9fd-c0e7f56544d3"
],
"operator": "q/contains"
}
]
}
}
}
]
}
}
]
})