Download the PHP package lenny4/doctrine-merge-persistent-collection-bundle without Composer
On this page you can find all versions of the php package lenny4/doctrine-merge-persistent-collection-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lenny4/doctrine-merge-persistent-collection-bundle
More information about lenny4/doctrine-merge-persistent-collection-bundle
Files in lenny4/doctrine-merge-persistent-collection-bundle
Package doctrine-merge-persistent-collection-bundle
Short Description Merge persistence collection when update entity
License MIT
Homepage https://github.com/lenny4/doctrine-merge-persistent-collection-bundle
Informations about the package doctrine-merge-persistent-collection-bundle
Merge persistence collection when update entity
This bundle is very usefull if you are using ApiPlatform and you don't want to send multiple requests when you update an entity and his children.
Installation
You can install the package via composer:
Usage
How does it work ?
Let's say you have 2 entities Father
and Son
as ApiResource
With these data in your database:
id | name |
---|---|
1 | father1 |
id | name | age | father_id |
---|---|---|---|
1 | son1 | 10 | 1 |
2 | son2 | 20 | 1 |
Let's say you want to update the name of the Father
from father1
to father2
and the age of 1 of his
children son1
only with 1 request. It's currently impossible only
with ApiPlatform. But with this Bundle you can do it now by
calling doctrineMergePersistentCollection->merge
as shown in the Usage.
- The first argument of the function take a
PersistentCollection
which correspond to all the sons of the father - The second argument is a callable which define how 2 sons are the same (in our example it's the
name
$son1->getName() === $son2->getName()
) - The second argument is a callable which define how to update a son if
$son1->getName() === $son2->getName()
return true;
Use case (example)
1) Add a son PUT /api/fathers/1
This will change the name of the father to father2
and add a son. Result:
id | name | age | father_id |
---|---|---|---|
1 | son1 | 10 | 1 |
2 | son2 | 20 | 1 |
3 | son3 | 30 | 1 |
2) Update son2 age PUT /api/fathers/1
This will change the name of the father to father2
and son2 age. Result:
id | name | age | father_id |
---|---|---|---|
1 | son1 | 10 | 1 |
2 | son2 | 30 | 1 |
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of doctrine-merge-persistent-collection-bundle with dependencies
doctrine/orm Version ^2.13
symfony/config Version ^6.1
symfony/dependency-injection Version ^6.1
symfony/http-kernel Version ^6.1