-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Update relations via set of ids or something like that #64
Comments
This is doable since the relation controls chain of persist commands, need to think about an API to avoid fetching... Let me think about it. |
@mrakolice technically it's possible when using Cycle, but are you sure it's a good idea to use Data mapper orm like this? |
$parent = [
'field1' => 'value'
'children' =>
[
['id' => 1],
['id' => 2],
['id' => 3],
]
]; All child entities exists in database, but child entity with So, when I going to do smth like this:
I can use only entities with $childIds = $parent->children->map(); // or load entities only with id via load method above
$entitiesToAdd = diff($ids, $childIds);
foreach ($orm->getRepository(Child::class)->where('id', 'in', $entitiesToAdd) as $child){
$parent->children->add($child);
}
$transaction->persist($parent);
$transaction->run(); This approach a bit sophisticated for me and I need to fetch entities to add from database, but this is just diff operation between two arrays, no matter - in php layer or sql layer. If I do something like this: $entities = $orm->getRepository(Child::class)->where('id', 'in', $entitiesToAdd);
$transaction = new Transaction();
foreach ($entities as $child){
$child->parent = $parent;
$transaction->persist($child);
}
$transaction->run(); This will be produce many update queries on sql layer. I can use UpdateQueryBuilder (and I've solved this problem exactly via QueryBuilder), but I think, that this problem very viable for many developers, that using Cycle ORM or any another ORM. =) |
I need to update HasMany and ManyToMany relations via set of ids, instead of loading entities that exists in database.
For example:
Child table
Child table
ORM should generate 2 update queries for nullable hasMany relations and 1 update and 1 delete query for not nullable hasMany relations and ManyToMany relations.
The text was updated successfully, but these errors were encountered: