|
46 | 46 | use Windwalker\Utilities\Assert\TypeAssert; |
47 | 47 | use Windwalker\Utilities\Attributes\AttributesAccessor; |
48 | 48 | use Windwalker\Utilities\Reflection\ReflectAccessor; |
49 | | -use Windwalker\Utilities\StrNormalize; |
50 | 49 | use Windwalker\Utilities\TypeCast; |
51 | 50 | use Windwalker\Utilities\Wrapper\RawWrapper; |
52 | 51 |
|
@@ -1055,17 +1054,30 @@ public function deleteWhere(mixed $conditions, ORMOptions|int $options = new ORM |
1055 | 1054 | $this->deleteBatch($conditions, $options); |
1056 | 1055 | } |
1057 | 1056 |
|
| 1057 | + |
| 1058 | + public function deleteOne(mixed $conditions, ORMOptions|int $options = new ORMOptions()): void |
| 1059 | + { |
| 1060 | + $this->deleteItems($conditions, true, $options); |
| 1061 | + } |
| 1062 | + |
1058 | 1063 | /** |
1059 | 1064 | * Find items and delete them one by one to trigger events. |
1060 | 1065 | * |
1061 | 1066 | * @param Conditions $conditions |
1062 | 1067 | * @param ORMOptions|int $options |
1063 | 1068 | * |
1064 | 1069 | * @return void |
1065 | | - * @throws \ReflectionException |
1066 | 1070 | */ |
1067 | 1071 | public function deleteBatch(mixed $conditions, ORMOptions|int $options = new ORMOptions()): void |
1068 | 1072 | { |
| 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 { |
1069 | 1081 | $options = clone ORMOptions::wrap($options); |
1070 | 1082 |
|
1071 | 1083 | // Event |
@@ -1159,6 +1171,10 @@ public function deleteBatch(mixed $conditions, ORMOptions|int $options = new ORM |
1159 | 1171 | if ($handleRelations) { |
1160 | 1172 | $metadata->getRelationManager()->delete($event->data, $entity); |
1161 | 1173 | } |
| 1174 | + |
| 1175 | + if ($once) { |
| 1176 | + break; |
| 1177 | + } |
1162 | 1178 | } |
1163 | 1179 | // Event |
1164 | 1180 | } |
|
0 commit comments