1
0
Fork 0
mirror of synced 2024-10-03 19:53:33 +13:00

Delete two way relationship attributes on collection delete

This commit is contained in:
Jake Barnby 2023-03-31 19:56:35 +13:00
parent bcf5b4bfab
commit fec374fe59
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -1046,6 +1046,21 @@ App::delete('/v1/databases/:databaseId/collections/:collectionId')
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove collection from DB'); 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()); $dbForProject->deleteCachedCollection('database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId());
$deletes $deletes