Skip to content

Commit f18f87f

Browse files
committed
deleteOne
1 parent fa6daa3 commit f18f87f

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/orm/src/EntityMapper.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use Windwalker\Utilities\Assert\TypeAssert;
4747
use Windwalker\Utilities\Attributes\AttributesAccessor;
4848
use Windwalker\Utilities\Reflection\ReflectAccessor;
49-
use Windwalker\Utilities\StrNormalize;
5049
use Windwalker\Utilities\TypeCast;
5150
use Windwalker\Utilities\Wrapper\RawWrapper;
5251

@@ -1055,17 +1054,30 @@ public function deleteWhere(mixed $conditions, ORMOptions|int $options = new ORM
10551054
$this->deleteBatch($conditions, $options);
10561055
}
10571056

1057+
1058+
public function deleteOne(mixed $conditions, ORMOptions|int $options = new ORMOptions()): void
1059+
{
1060+
$this->deleteItems($conditions, true, $options);
1061+
}
1062+
10581063
/**
10591064
* Find items and delete them one by one to trigger events.
10601065
*
10611066
* @param Conditions $conditions
10621067
* @param ORMOptions|int $options
10631068
*
10641069
* @return void
1065-
* @throws \ReflectionException
10661070
*/
10671071
public function deleteBatch(mixed $conditions, ORMOptions|int $options = new ORMOptions()): void
10681072
{
1073+
$this->deleteItems($conditions, false, $options);
1074+
}
1075+
1076+
protected function deleteItems(
1077+
mixed $conditions,
1078+
bool $once = false,
1079+
ORMOptions|int $options = new ORMOptions()
1080+
): void {
10691081
$options = clone ORMOptions::wrap($options);
10701082

10711083
// Event
@@ -1159,6 +1171,10 @@ public function deleteBatch(mixed $conditions, ORMOptions|int $options = new ORM
11591171
if ($handleRelations) {
11601172
$metadata->getRelationManager()->delete($event->data, $entity);
11611173
}
1174+
1175+
if ($once) {
1176+
break;
1177+
}
11621178
}
11631179
// Event
11641180
}

packages/orm/src/ORMProxyTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ public function deleteWhere(
407407
$this->deleteBatch($entityClass, $conditions, $options);
408408
}
409409

410+
public function deleteOne(string $entityClass, mixed $conditions, ORMOptions|int $options = new ORMOptions()): void
411+
{
412+
$this->mapper($entityClass)->deleteOne($conditions, $options);
413+
}
414+
410415
/**
411416
* Find items and delete them one by one to trigger events.
412417
*

0 commit comments

Comments
 (0)