1
0
Fork 0
mirror of synced 2024-07-02 21:20:58 +12:00

Update related two way attribute

This commit is contained in:
Jake Barnby 2023-03-31 18:38:37 +13:00
parent 3bbe6d4da8
commit bcf5b4bfab
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -228,7 +228,7 @@ function updateAttribute(
throw new Exception(Exception::COLLECTION_NOT_FOUND);
}
$attribute = $dbForProject->getDocument('attributes', ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key));
$attribute = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key);
if ($attribute->isEmpty()) {
throw new Exception(Exception::ATTRIBUTE_NOT_FOUND);
@ -319,15 +319,24 @@ function updateAttribute(
}
if ($type === Database::VAR_RELATIONSHIP) {
$options = array_merge($attribute->getAttribute('options', []), $options);
$options = \array_merge($attribute->getAttribute('options', []), $options);
$attribute->setAttribute('options', $options);
$dbForProject->updateRelationship(
collection: $collectionId,
key: $key,
twoWay: $options['twoWay'],
onDelete: $options['onDelete'],
);
if ($options['twoWay']) {
$relatedCollection = $dbForProject->getDocument('database_' . $db->getInternalId(), $options['relatedCollection']);
$relatedAttribute = $dbForProject->getDocument('attributes', $db->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey']);
$relatedOptions = \array_merge($relatedAttribute->getAttribute('options'), $options);
$relatedAttribute->setAttribute('options', $relatedOptions);
$dbForProject->updateDocument('attributes', $db->getInternalId() . '_' . $relatedCollection->getInternalId() . '_' . $options['twoWayKey'], $relatedAttribute);
$dbForProject->deleteCachedDocument('database_' . $db->getInternalId(), $relatedCollection->getId());
}
} else {
$dbForProject->updateAttribute(
collection: $collectionId,