fix: Table relationship rich editor attributes

This commit is contained in:
Dan Harrin
2025-09-16 10:20:13 +01:00
parent 85f762ab35
commit 0b1d7a44e1
+39 -33
View File
@@ -103,6 +103,44 @@ trait HasCellState
public function getStateFromRecord(): mixed
{
$record = $this->getRecord();
if ($record instanceof Model) {
$relationship = $this->getRelationship($record);
if ($relationship) {
$relationshipAttribute = $this->getFullAttributeName($record);
$state = collect($this->getRelationshipResults($record))
->reduce(
function (Collection $carry, Model $record) use ($relationshipAttribute): Collection {
if (
($record instanceof HasRichContent) &&
$record->hasRichContentAttribute($relationshipAttribute)
) {
$state = $record->getRichContentAttribute($relationshipAttribute);
} else {
$state = data_get($record, $relationshipAttribute);
}
if (blank($state)) {
return $carry;
}
return $carry->push($state);
},
initial: collect(),
)
->when($this->isDistinctList(), fn (Collection $state) => $state->unique())
->values();
if (! $state->count()) {
return null;
}
return $state->all();
}
}
$name = $this->getName();
if (
@@ -114,39 +152,7 @@ trait HasCellState
$state = data_get($record, $name);
}
if ($state !== null) {
return $state;
}
if (($this instanceof Column) && is_array($record)) { /** @phpstan-ignore function.impossibleType, booleanAnd.alwaysFalse */
return null;
}
if (! $this->hasRelationship($record)) {
return null;
}
$relationship = $this->getRelationship($record);
if (! $relationship) {
return null;
}
$attributeName = $this->getAttributeName($record);
$fullAttributeName = $this->getFullAttributeName($record);
$state = collect($this->getRelationshipResults($record))
->filter(fn (Model $record): bool => array_key_exists($attributeName, $record->attributesToArray()))
->pluck($fullAttributeName)
->filter(fn ($state): bool => filled($state))
->when($this->isDistinctList(), fn (Collection $state) => $state->unique())
->values();
if (! $state->count()) {
return null;
}
return $state->all();
return $state;
}
public function clearCachedState(): void