Skip to content

Commit

Permalink
fix: HasMany
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Nov 30, 2024
1 parent fcbe8c9 commit 59fa6a5
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Laravel/src/Fields/Relationships/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,19 +346,23 @@ protected function getTablePreview(): TableBuilderContract
$resource = clone $this->getResource()
->disableSaveQueryState();

$resource->disableQueryFeatures();
if(\is_null($this->modifyBuilder) && $this->getRelatedModel()?->relationLoaded($this->getRelationName()) === true) {
$items = $this->toRelatedCollection();
} else {
$resource->disableQueryFeatures();

$casted = $this->getRelatedModel();
$relation = $casted?->{$this->getRelationName()}();
$casted = $this->getRelatedModel();
$relation = $casted?->{$this->getRelationName()}();

/** @var Builder $query */
$query = \is_null($this->modifyBuilder)
? $relation
: value($this->modifyBuilder, $relation);
/** @var Builder $query */
$query = \is_null($this->modifyBuilder)
? $relation
: value($this->modifyBuilder, $relation);

$resource->customQueryBuilder($query->limit($this->getLimit()));
$resource->customQueryBuilder($query->limit($this->getLimit()));

$items = $resource->getQuery()->get();
$items = $resource->getQuery()->get();
}

return TableBuilder::make(items: $items)
->fields($this->getFieldsOnPreview())
Expand Down

0 comments on commit 59fa6a5

Please sign in to comment.