-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Chained data persisters #1313
Comments
For the priority just use the tag priority (https://symfony.com/doc/current/service_container/tags.html#tagged-services-with-priority) Also indeed decoration on the doctrine persister makes sense but the ChainDataPersister chains your data persisters you don't need them to decorate themselves. See https://github.com/api-platform/core/blob/main/src/DataPersister/ChainDataPersister.php. Feel free to improve our documentation it'd be greatly appreciated! |
Many thanks, I would like to improve the documentation, but I still don't understand if ChainDataPersister should work as I described. In order to get things as documented, I have to manually inject the Doctrine DataPersister into every argument. Is it right? |
Mhh I would not do this. A common DataPersister that you can decorate is the |
Sorry, I don't know if you got the point on what happens and what my question is. If I use the |
it's not api platform it's symfony and the decoration pattern: https://symfony.com/doc/current/service_container/service_decoration.html maybe start by there and things will get clearer.
No it should only decorate the doctrine ORM data persister (https://github.com/api-platform/core/blob/main/src/Bridge/Doctrine/Common/DataPersister.php). |
Now I get it, didn't know it was a Symfony feature! |
- explain how to avoid "vertical" DataPersisters chaining (api-platform#1313) - explicit how to use tag priority (api-platform#540)
Hi, I'm noticing a strange behaviour with data persisters.
I would like to have a UserDataPersister to send e-mails and handling invitation, registration, activation and so on.
Then a ProductDataPersister that will handle some business logic about our product.
After that, I would like to have a SoftDeleteableDataPersister that handle the deletions of Users, Products and everything else that implement a specific interface.
Clearly, UserDataPersister supports
$data instanceof User::class
, ProductDataPersister supports$data instanceof Product::class
and SoftDeleteableDataPersister supports$data instanceof SoftDeleteableInterface
This is my services.yml:
after doing that, I found a DeleteableDataPersister that decorates UserDataPersister that decorates ProductDataPersister that decorates Doctrine\Common\DataPersister. Shouldn't chained mean that they should run in parallel?
Also, if one of those is a DataPersister while the others are ContextAwareDataPersisters, autocomposition won't work (nothing could work like this!
To get the right thing, I have to do something like this, which is not documented:
Also, I would like the Deleteable to be checked first and be resumable, and the others to be executed later and not be resumable, because I don't want Doctrine Data Persister to be executed. As asked in #540 is it possible to set an order for data persisters?
The text was updated successfully, but these errors were encountered: