Can a link that's effectively many-to-many be implemented by a many-to-one link that uses an array of pks to link?

can a link that’s effectively many-to-many be implemented by a many-to-one link that uses an array of pks to link? Example: a Route has a col that is an array of Road Segment pks and links the two objects via many-to-one. One Road Segment can have many Routes bc a road segment can be included in multiple Routes . In this view it shoes that one Route has only one Road segment but I assume in reality a Route will link to multiple Road segments via the pk array column. Do I have that right?

1 Like

Evidently–the answer is YES. You can use a one-to-many with pk array to create an effective many-to-many link :slight_smile:

Note that this link does NOT work as expected in Functions:

Expected at most one linked object. Check if the cardinality of the object in the link should be set to ‘MANY’ instead or if there are erroneous links in the data…
Error Parameters: {
“objectLocator”: “[rid: ri.phonograph2-objects.main.object.ac5b5c51-5f67-4e5e-84aa-b2c6b7642eda, type: salmketb.ngds-route, primaryKey: {"primary_key":"31e8a527-a9b1-43fc-9fba-fa65992e0ea8"}]”,
“relationId”: “salmketb.ngds-road-segment-ngds-route1”,
“relationSide”: “TARGET”,
“actualLength”: “4”
}
SafeError: Expected at most one linked object. Check if the cardinality of the object in the link should be set to ‘MANY’ instead or if there are erroneous links in the data.
at t [as constructor] (FunctionsIsolateRuntimePackage:2:1310795)
at new t (FunctionsIsolateRuntimePackage:2:540085)
at Object.t.expectedOnlySingleLink (FunctionsIsolateRuntimePackage:2:1191649)
at t.DefaultObjectStorageProvider.assertSingleLink (FunctionsIsolateRuntimePackage:2:1187902)
at FunctionsIsolateRuntimePackage:2:1186939
at t.ExternalRequestTracer.sync (FunctionsIsolateRuntimePackage:2:1307252)
at Object.get (FunctionsIsolateRuntimePackage:2:1186761)
at Object.get (FunctionsIsolateRuntimePackage:2:1113674)
at Object.get (FunctionsIsolateRuntimePackage:2:1115556)
at Object.get (FunctionsIsolateRuntimePackage:2:1118956)

Yes, this is a problem! Can we please add the possibility in the ontology manager to define m-to-n relations via arrays of foreign keys? Having the array of foreign keys has several advantages when it comes to materializing objects since the relation is contained in the data. Also when using the Foundry API, it is not possible to get access to the join tables for standard m-to-n relations which makes joining the data in hindsight impossible…

It feels arbitrary that it works in Workshop but not in Functions on Objects / SDKs

#Feature request :wink:

2 Likes

Hi Flackermann,

Thank you for your question and for raising this point.
I wanted to kindly clarify what you mean by “m-to-n relations”?
Are you referring to “Many-to-None,” or something else?

Regards

I think its many to many, but m and n just mean different numbers. :slight_smile:

source: m and n are used as replacement for numbers in math all the time. It’s like using x-to-y

2 Likes

Yes, this is accurate. We often talk about many-to-many as m-to-n relations. and many-to-one as n-to-1 or 1-to-n depending on the context.

1 Like

Got it; many thanks :blush:

Does the Many to Many link via an ontology object satisfy this criteria? It give you full control over the join table. https://www.palantir.com/docs/foundry/object-link-types/create-link-type/#object-backed-links

Not necessarily… The really big advantage of having an array of foreign keys is that it is ordered. Object sets are not. If you would have an order index on the many-to-many object type, this would not result in ordered searcharounds. In my current usecase, I create a Plot-object that links via the foreign key array to the value objects and the order of foreign keys is maintained in the order of the categorical x-axis so that users can re-order barcharts to optimize their charts for certain aspects in discussions.

1 Like

Very interesting! Thank you for the response.