Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
May 20, 2023

Conversation

ksuess
Copy link
Member

@ksuess ksuess commented May 18, 2023

source, target, relationname.

source, target, relationname.
But mark source as modified.
@mister-roboto
Copy link

@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 ksuess requested a review from pbauer May 18, 2023 14:59
Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].

@ksuess
Copy link
Member Author

ksuess commented May 18, 2023

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.

do not mark as modified if relation already exists
@ksuess
Copy link
Member Author

ksuess commented May 20, 2023

@jenkins-plone-org please run jobs

@ksuess ksuess requested review from pbauer and removed request for pbauer May 20, 2023 09:19
@pbauer pbauer merged commit 634bc95 into master May 20, 2023
@pbauer pbauer deleted the create-relation branch May 20, 2023 12:10
@ksuess ksuess mentioned this pull request May 22, 2023
12 tasks
@ksuess
Copy link
Member Author

ksuess commented May 22, 2023

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

@mauritsvanrees
Copy link
Sponsor Member

Sure. I have released plone.api 2.0.3.

@ksuess
Copy link
Member Author

ksuess commented May 22, 2023

Sure. I have released plone.api 2.0.3.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants