Update builder¶
Use UpdateBuilder for set-based updates.
use Small\SwooleEntityManager\QueryBuilder\RelationalQueryBuilder\Enum\ConditionOperatorType;
$update = $userManager->createUpdateBuilder('user');
$update
->addFieldToUpdate('enabled', false)
->where()
->firstCondition(
$update->getFieldForCondition('lastLoginAt'),
ConditionOperatorType::inferior,
':threshold',
);
$update->setParameter('threshold', new \DateTimeImmutable('-1 year')->format('Y-m-d H:i:s'));
$userManager->executeUpdate($update);
addFieldToUpdate() accepts an entity field name. Conditions and parameters use the same API as the select builder.
Lifecycle callbacks¶
By default, executeUpdate($builder) performs one native bulk statement and skips entity callbacks.
When trigger execution is requested and the entity implements update or persist lifecycle interfaces, the manager first selects matching entities and persists them one by one. This is slower but executes callbacks.
Unsupported operations¶
Update builders do not support joins, ordering, offsets or limits. Calling those operations throws LogicException. Convert the update to a select query when you need to inspect the matching rows: