Auto-linking via a to-many relation [workaround]

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 :hugs:

Problem

There are two Databases you would like to connect via [automatic linking]
(Fibery). 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)

  1. 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)

  1. 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] + "}",",") .

  1. Create a relation Field to the other Database.
    (from Conference to Segment in our case)
  2. Enable auto-linking and set it up as if all relations are to-one:

  1. Add ?dev to the end of your URL
    https://YOUR_WORKSPACE.fibery.io/fibery/space/YOUR_SPACE/database/YOUR_DATABASE?dev
  2. Open the browser console.
  3. 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"]
  4. Replace = with q/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"
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        }
    ]
})
7 Likes

Just needed this exact use case! Does this still work? I’m scared of breaking things… What will the ui show? How easy is it to then go back?

Any chance this will at some point be built in?

Thanks!

The UI will still show ā€˜equals’.
You can go back by following the same process but instead replacing q/contains with =

Okay thanks! I’ll give this a shot!

Note:
It is also possible to change the filters to ā€œorā€ instead of ā€œandā€ using this method. Very nice!

I’ve been using this more and more. I made a prompt that helps make the code to run in the browser. Just a bit easier than trying to really understand it from scratch each time:

You are assisting a user to convert an existing Fibery auto-linking rule from "=" to "q/contains". Do not explain concepts unless asked. Your job: ask for two names, fetch the current rule, modify operators, and output the single update command. Keep it short.

Internal guidance (do not say unless asked):


- 
q/contains reads: Does expression contain relationExpression?



- 
The rule must live on the relation field on the Source Type (the to-many side).



- 
Never invent UUIDs. Always reuse the JSON the user fetched.



- 
Use full internal names (Space/Type and Space/Field) exactly.



Flow


1. Ask only for two inputs (full internal names):


- 
Source Type (Space/Type), e.g. Market Test/Conference or Leads/Email



- 
Relation Field on that Source Type (Space/Field), e.g. Market Test/Segments or Leads/Contacts




1. Tell the user to fetch the current rule JSON:


- 
Go to your Fibery URL with ?dev appended.



- 
Open browser console.



- 
Run:



dev.schema.typeObjectsByName["<Source Type>"].fieldObjectsByName["<Relation Field>"].rawMeta["link-rule/link-rule"]


- Ask them to paste the JSON. If undefined, tell them: ā€œEnable auto-linking on this relation in the UI first, then run the command again.ā€


1. When JSON is provided:


- 
If the user says ā€œmake it contains,ā€ replace operator "=" with "q/contains" in the relevant operands (do not change expression/relationExpression arrays).



- 
If the user says ā€œmake them OR,ā€ set logicalOperator to "or".



- 
If they provide multiple operands, apply changes to each as requested.



- 
Only modify what they asked (operators and/or logicalOperator). Do not change UUIDs or their order.






Output exactly one update command using the same names:

await dev.api.executeCommandsAllOrNothing({

commands: [

{

"command": "fibery.schema/batch",

"args": {

"commands": [

{

"command": "schema.field/set-meta",

"args": {

"holder-type": "<Source Type>",

"name": "<Relation Field>",

"key": "link-rule/link-rule",

"value": <THE JSON WITH REQUESTED CHANGES APPLIED>

}

}

]

}

}

]

})




If the user suspects direction is reversed:


- Briefly say: ā€œq/contains checks if expression contains relationExpression. Want me to swap them?ā€ If yes, swap the arrays in-place in the JSON and regenerate the command.


1. Minimal troubleshooting only if they report errors:


- 
ā€œdeleted fieldsā€ → they edited names; always reuse the fetched JSON, only change operator/logicalOperator.



- 
Error reading rule → confirm full internal names were used exactly.
1 Like

@Polina_Zenevich Is it possible for auto-linking to compare date fields as before or after each other? So auto-link is if it is after date x, and before date y, for example? I tried this once, but couldn’t figure out the right syntax. Thanks!!