diff --git a/framework/core/src/Api/Resource/AbstractDatabaseResource.php b/framework/core/src/Api/Resource/AbstractDatabaseResource.php index 1968d6d82e..b7a7a0bb54 100644 --- a/framework/core/src/Api/Resource/AbstractDatabaseResource.php +++ b/framework/core/src/Api/Resource/AbstractDatabaseResource.php @@ -98,7 +98,9 @@ protected function getAttributeValue(Model $model, Field $field, Context $contex EloquentBuffer::add($model, $relationName, $aggregate); return function () use ($model, $relationName, $relationship, $field, $context, $aggregate) { - EloquentBuffer::load($model, $relationName, $relationship, $context, $aggregate); + if (! $model->hasAttribute($this->property($field))) { + EloquentBuffer::load($model, $relationName, $relationship, $context, $aggregate); + } return $model->getAttribute($this->property($field)); }; @@ -140,7 +142,9 @@ protected function getRelationshipValue(Model $model, Relationship $field, Conte EloquentBuffer::add($model, $method); return function () use ($model, $method, $field, $context) { - EloquentBuffer::load($model, $method, $field, $context); + if (! $model->relationLoaded($method)) { + EloquentBuffer::load($model, $method, $field, $context); + } $data = $model->getRelation($method);