Skip to content

ExportAction not working on ManageRelatedRecords page #233

@marvinrabe

Description

@marvinrabe

Since the release of Filament v4 and your package's v3, the functionality with ManageRelatedRecords pages has stopped working correctly. I am getting an mostly empty Excel file with the correct column headers but without any table data.

When passing the record of the page to the export function in the following line:

'records' => property_exists($livewire, 'record') ? collect([$livewire->record]) : null,

it results in an incorrect query. For instance, in a scenario where a parent model is involved and its related items are the children of said model, the query generated is as follows (with 23 being the ID of the parent entity):

SELECT * FROM "related_items" 
WHERE "related_items"."parent_id" = 23 
AND "related_items"."parent_id" IS NOT NULL 
AND "related_items"."id" IN (23) 
ORDER BY "related_items"."id" ASC, "driver" ASC;

The issue lies in the condition AND "related_items"."id" IN (23), as 23 is a parent ID, not a related item ID. This was added to the query by these lines:

return $this->query = $query
->when(
$this->recordIds,
fn ($query) => $model->getKeyType() === 'string'
? $query->whereIn($this->modelKeyName, $this->recordIds)
: $query->whereIntegerInRaw($this->modelKeyName, $this->recordIds)
);

I expected all related items to be selected, but with this condition the query result is empty.

I attempted to create a custom version of ExportAction without passing the record parameter, as shown below:

public function handleExport(array $data)
{
    $exportable = $this->getSelectedExport($data);
    $livewire = $this->getLivewire();

    return app()->call([$exportable, 'hydrate'], [
        'livewire' => $this->getLivewire(),
        'records' => null, // THIS LINE WAS CHANGED
        'formData' => data_get($data, $exportable->getName()),
    ])->export();
}

With this change, the SQL looks fine, but I still encounter an error:

The column [xyz] is not mounted to a table.

Where xyz is a valid column defined in the form schema function.

I am unsure how to resolve this issue. Any guidance on using ExportActions on ManageRelatedRecords page would help. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions