Delete two way relationship attributes on collection delete
This commit is contained in:
parent
bcf5b4bfab
commit
fec374fe59
1 changed files with 15 additions and 0 deletions
|
@ -1046,6 +1046,21 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId')
|
|||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove collection from DB');
|
||||
}
|
||||
|
||||
$relationships = \array_filter(
|
||||
$collection->getAttribute('attributes'),
|
||||
fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP
|
||||
);
|
||||
|
||||
foreach ($relationships as $relationship) {
|
||||
if (!$relationship['twoWay']) {
|
||||
continue;
|
||||
}
|
||||
$relatedCollection = $dbForProject->getDocument('database_' . $database->getInternalId(), $relationship['relatedCollection']);
|
||||
$dbForProject->deleteDocument('attributes', $database->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $relationship['twoWayKey']);
|
||||
$dbForProject->deleteCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId());
|
||||
$dbForProject->deleteCachedCollection('database_' . $database->getInternalId() . '_collection_' . $relatedCollection->getInternalId());
|
||||
}
|
||||
|
||||
$dbForProject->deleteCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId());
|
||||
|
||||
$deletes
|
||||
|
|
Loading…
Reference in a new issue