plone / plone.api

The Plone API
https://6.docs.plone.org/plone.api
Other
86 stars 53 forks source link

Create relation only if there is no existing one with same … #507

Closed ksuess closed 1 year ago

ksuess commented 1 year ago

source, target, relationname.

mister-roboto commented 1 year ago

@ksuess thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

ksuess commented 1 year ago

It would be good to add a sentence or two to the documentation with this detail. I've also modified an existing sentence. I'm not sure if the new suggestion is 100% correct

https://6.docs.plone.org/plone.api/relation.html#create-relation

If the relation is based on a `RelationChoice` or `RelationList` field on the source object, then the value of that field is created or updated accordingly.

When calling {meth}`create()`, if a relation with the same `source`, `target`, or `relationship` does not exist, then it creates the relation and marks the `source` as modified. However if the relation exists, then [something else happens or doesn't].

It's just a bug fix for #508 By now with api.relation.create called twice with the same arguments for a relation type like for example relatedItems, it would add two times the same related item (two RelationValues to the field value). Therefore I do not see the need for a change of the documentation.

The thing I am not happy about, is that the method returns in both cases None. But this is in my eyes of low priority and can be handled later in a separate issue.

ksuess commented 1 year ago

@jenkins-plone-org please run jobs

ksuess commented 1 year ago

@mauritsvanrees May this be released, please. It's needed for administering relations in the upcoming relations control panel https://github.com/plone/volto/pull/3382

mauritsvanrees commented 1 year ago

Sure. I have released plone.api 2.0.3.

ksuess commented 1 year ago

Sure. I have released plone.api 2.0.3.

Thank you!