From 464b67f8489124f85826e72e44de920a007904ed Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Sat, 23 Nov 2024 09:31:38 +0100 Subject: [PATCH] fix: skip resource eager loading if manually eager loaded --- .../core/src/Api/Resource/AbstractDatabaseResource.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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);