Is there a way to update every record in an entity collection that results in one SQL query? Looping through individual records requires more time and database traffic than a single query. I often write raw SQL to speed up hooks and services, which I would like to avoid. The following two examples happen all the time in my system:
The number of queries is equal to the number of entities in the collection; however, each update could happen in a single query. I am aware of the Query Builder, but I haven't figured out how to use it yet because it is complicated. This seems like a common thing to want to do, so native support from EntityCollection would be awesome.
PHP Code:
foreach($claims as $claim) {
$claim->set(array(
"dateSubmitted" => (new Datetime())->format("Y-m-d H:i:s"),
"status" => "Submitted",
));
$this->entityManager->saveEntity($claim);
}
PHP Code:
foreach($claims as $claim) {
$this->entityManager->getRDBRepository("Document")
->getRelation($document, "claims")->relate($claim);
}
Comment