You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/private/AppFramework/ORM/EntityInfo.php
+27-16Lines changed: 27 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -13,14 +13,15 @@
13
13
useOCP\AppFramework\ORM\Attribute\JoinColumn;
14
14
useOCP\AppFramework\ORM\Attribute\ManyToOne;
15
15
useOCP\AppFramework\ORM\Attribute\OneToOne;
16
+
useOCP\DB\Types;
16
17
17
18
/**
18
19
* @template T as object
19
20
*/
20
-
class EntityInfo {
21
+
finalclass EntityInfo {
21
22
publicreadonlystring$tableName;
22
23
23
-
/** @var array<string, string> */
24
+
/** @var array<string, Types::*> */
24
25
publicarray$mappingColumnToTypes = [];
25
26
26
27
/** @var array<string, string> */
@@ -77,55 +78,65 @@ public function __construct(
77
78
}
78
79
}
79
80
80
-
if ($propertyAttributes->id!== null && $propertyAttributes->column=== null) {
81
+
if ($propertyAttributes->idinstanceof Id && !$propertyAttributes->columninstanceof Column) {
81
82
thrownew \RuntimeException($this->entityClass . ' has a Id attribute on ' . $property->getName() . ' but not the corresponding required Column attribute.');
82
83
}
83
84
84
-
if ($propertyAttributes->oneToOne!== null
85
+
if ($propertyAttributes->oneToOneinstanceof OneToOne
thrownew \RuntimeException($this->entityClass . '::' . $property->getName() . ' sets JoinColumn::$onDelete on the mappedBy (inverse) side of a OneToOne relation, where it has no effect. Set it on the owning (invertedBy) side instead.');
89
90
}
90
91
91
-
if ($propertyAttributes->oneToOne!== null && $propertyAttributes->oneToOne->mappedBy !== null) {
if ($targetOneToOne === null || $targetOneToOne->invertedBy === null) {
120
-
thrownew \RuntimeException($prefix . $oneToOne->targetEntity . '::' . $oneToOne->mappedBy . ' is not the owning (invertedBy) side of a OneToOne relation.');
131
+
thrownew \RuntimeException($prefix . $oneToOne->targetEntity . '::' . $mappedBy . ' is not the owning (invertedBy) side of a OneToOne relation.');
121
132
}
122
133
123
134
if ($targetOneToOne->invertedBy !== $property->getName()) {
@@ -92,17 +94,18 @@ public function insert(object $entity): object {
92
94
if ($property->getValue($entity) !== null) {
93
95
thrownew \LogicException($entity::class . '::' . $property->getName() . ' is the mappedBy (inverse) side of a OneToOne relation and cannot be persisted directly; set it from the owning (invertedBy) side instead.');
@@ -208,11 +213,12 @@ public function delete(object $entity): void {
208
213
209
214
try {
210
215
$delete->executeStatement();
211
-
} catch (Exception$e) {
212
-
if ($e->getReason() === Exception::REASON_FOREIGN_KEY_VIOLATION) {
213
-
thrownew \LogicException($entityClass . ' cannot be deleted: another entity still references it. Delete the related entity first, or set onDelete: \'CASCADE\' on the owning JoinColumn.', 0, $e);
216
+
} catch (Exception$exception) {
217
+
if ($exception->getReason() === Exception::REASON_FOREIGN_KEY_VIOLATION) {
218
+
thrownew \LogicException($entityClass . " cannot be deleted: another entity still references it. Delete the related entity first, or set onDelete: 'CASCADE' on the owning JoinColumn.", 0, $exception);
214
219
}
215
-
throw$e;
220
+
221
+
throw$exception;
216
222
}
217
223
}
218
224
@@ -222,14 +228,16 @@ public function delete(object $entity): void {
0 commit comments