๐ Several entities broken insert order
gam6itko opened this issue ยท 1 comments
gam6itko commented
No duplicates ๐ฅฒ.
- I have searched for a similar issue in our bug tracker and didn't find any solutions.
What happened?
If you save multiple related entities in the same transaction, there may be saved in broken order.
$em = (new EntityManager($orm));
$em->persist($user);
$i = 1;
$em->persist(new User\Alias($user, "{$user->age}-$i")) and $i++;
$em->persist(new User\Email($user, "{$user->age}-$i")) and $i++;
$em->persist(new User\Email($user, "{$user->age}-$i")) and $i++;
$em->persist(new User\Phone($user, "{$user->age}-$i")) and $i++;
$em->persist(new User\Phone($user, "{$user->age}-$i")) and $i++;
$em->persist(new User\Phone($user, "{$user->age}-$i")) and $i++;
$em->run();
will be saved in db in broken order
{
"alias": [
{
"value": "246-1"
}
],
"email": [
{
"value": "246-2"
},
{
"value": "246-3"
}
],
"phone": [
{
"value": "246-6"
},
{
"value": "246-4"
},
{
"value": "246-5"
}
]
}
Bug demo: gam6itko/app@70024f6
Bug detected on:
http://localhost:8080/issue1
http://localhost:8080/issue2
http://localhost:8080/issue3
Bug NOT detected on:
http://localhost:8080/no_issue1
http://localhost:8080/no_issue2
Version
ORM 2.2.0
PHP 8.1.2
cycle/annotated v3.2.0 Cycle ORM Annotated Entities generator
cycle/database 2.2.2 DBAL, schema introspection, migration and pagination
cycle/migrations v4.0.0 Database migrations, migration scaffolding
cycle/orm v2.2.0 PHP DataMapper ORM and Data Modelling Engine
cycle/schema-builder v2.1.0 Cycle ORM Schema Builder
cycle/schema-migrations-generator 3.x-dev df0e391 Cycle ORM Migration generation
cycle/schema-renderer 1.1.0 Utils for Cycle ORM Schema rendering
gam6itko commented
The big trouble if I try to delete and insert entities with unique index.
See here: https://github.com/cycle/orm/actions/runs/7699320457/job/20980653390?pr=381#step:11:38