Defining a `relationship` through a DX schema vs. plone.api?

plone.api.relation support the creation of relations between objects with a particular relationship:

43. Relations – Mastering Plone 6 Development — Plone Training 2021 documentation.

However, how would you configure the relationship as part of Dexterity relation field (choice or list). I can not find anything here:

What about 43. Relations – Mastering Plone 6 Development — Plone Training 2021 documentation?

Philip talks in detail about this in is Plone Conference 2021 talk: Why Relations are Awesome - Philip Bauer - YouTube

1 Like

That‘s the same link :slight_smile:

No, you linked to “43.10. Interacting with relations and backrelations in code”, I linked to “43.1. Creating relations in a schema” :upside_down_face: . But is’s the same document

Yes, but I don't see how to defined the classification of a relation using a relationship parameter. A relation between a source and target object is always associated with related relationship string. I think, relatedItem (or so is used) for related items..but in many cases you what a different classification for a custom relationship.

The name of the relationship is the name of the field (not like in AT where these were separate values).
If you have a relationfield (choice or list) with the name friend the call api.relation.create(source=x, target=y, relationship="friend") creates such a relation and sets that relationValue as a value in that field on x. If there is no field, the relation is created without changing the value of the field.

1 Like

@pbauer Mean "set" remove all old relations an set the new, as the only one. or is this an "append"-operation for fill a list with relationes?

for lists it is append, for choice it is replace. See plone.api/relation.py at master · plone/plone.api · GitHub

Sorry, it is create, not set

ok, this information is missing from the docs (and not directly obvious).
From the developer's prospective, it would be handy if you could specify the relationship name explicitly.