moved formatting logic to relationship attribute model
This commit is contained in:
parent
52e800cc59
commit
7e185cd799
2 changed files with 20 additions and 15 deletions
|
@ -1718,20 +1718,6 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes')
|
|||
$filterQueries = Query::groupByType($queries)['filters'];
|
||||
$total = $dbForProject->count('attributes', $filterQueries, APP_LIMIT_COUNT);
|
||||
|
||||
//Add relationship data from options to attributes as it loses options during response setup
|
||||
foreach ($attributes as $attribute) {
|
||||
if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) {
|
||||
$options = $attribute->getAttribute('options');
|
||||
if (!\is_null($options)) {
|
||||
$attribute->setAttribute('relatedCollection', $options['relatedCollection']);
|
||||
$attribute->setAttribute('relationType', $options['relationType']);
|
||||
$attribute->setAttribute('twoWay', $options['twoWay']);
|
||||
$attribute->setAttribute('twoWayKey', $options['twoWayKey']);
|
||||
$attribute->setAttribute('side', $options['side']);
|
||||
$attribute->setAttribute('onDelete', $options['onDelete']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$output = $response->output(new Document([
|
||||
'total' => $total,
|
||||
'attributes' => $attributes,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Appwrite\Utopia\Response\Model;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
|
||||
use Utopia\Database\Document;
|
||||
class AttributeRelationship extends Attribute
|
||||
{
|
||||
public function __construct()
|
||||
|
@ -73,4 +73,23 @@ class AttributeRelationship extends Attribute
|
|||
{
|
||||
return Response::MODEL_ATTRIBUTE_RELATIONSHIP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process Document before returning it to the client
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public function filter(Document $document): Document
|
||||
{
|
||||
$options = $document->getAttribute('options');
|
||||
if (!\is_null($options)) {
|
||||
$document->setAttribute('relatedCollection', $options['relatedCollection']);
|
||||
$document->setAttribute('relationType', $options['relationType']);
|
||||
$document->setAttribute('twoWay', $options['twoWay']);
|
||||
$document->setAttribute('twoWayKey', $options['twoWayKey']);
|
||||
$document->setAttribute('side', $options['side']);
|
||||
$document->setAttribute('onDelete', $options['onDelete']);
|
||||
}
|
||||
return $document;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue