Merge pull request #9225 from appwrite/fix-empty-related-attribute

Add relatedCollection default
This commit is contained in:
Jake Barnby 2025-01-15 22:08:23 +13:00 committed by GitHub
commit 2f83bec071
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -136,6 +136,9 @@ class Databases extends Action
$options = $attribute->getAttribute('options', []);
$project = $dbForPlatform->getDocument('projects', $projectId);
$relatedAttribute = new Document();
$relatedCollection = new Document();
try {
switch ($type) {
case Database::VAR_RELATIONSHIP:
@ -175,7 +178,7 @@ class Databases extends Action
if ($e instanceof DatabaseException) {
$attribute->setAttribute('error', $e->getMessage());
if (isset($relatedAttribute)) {
if (! $relatedAttribute->isEmpty()) {
$relatedAttribute->setAttribute('error', $e->getMessage());
}
}
@ -186,7 +189,7 @@ class Databases extends Action
$attribute->setAttribute('status', 'failed')
);
if (isset($relatedAttribute)) {
if (! $relatedAttribute->isEmpty()) {
$dbForProject->updateDocument(
'attributes',
$relatedAttribute->getId(),
@ -198,7 +201,7 @@ class Databases extends Action
} finally {
$this->trigger($database, $collection, $attribute, $project, $projectId, $events);
if ($type === Database::VAR_RELATIONSHIP && $options['twoWay']) {
if (! $relatedCollection->isEmpty()) {
$dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId());
}
@ -364,7 +367,7 @@ class Databases extends Action
} finally {
$dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $collectionId);
if (!$relatedCollection->isEmpty() && !$relatedAttribute->isEmpty()) {
if (! $relatedCollection->isEmpty()) {
$dbForProject->purgeCachedDocument('database_' . $database->getInternalId(), $relatedCollection->getId());
}
}