Queued exports that use FromQuery ignores eagerLoaded relationships.
class UserExport implements FromQuery, WithMapping, ShouldQueue
{
use Exportable;
public function query()
{
return User::with(['team']);
}
public function map($user): array
{
return [
$user->id,
$user->name,
$user->team->name,
$user->team->location,
];
}
}
Expected behavior:
The query should eager load the belongsTo team relationship.
Actual behavior:
The SerializedQuery job only serializes the main query without the eagerLoad property. This results in an N+1 issue anytime a cell is mapped to data from a related table. This could cause a significant performance hit on large queries.
We indeed don't keep the eager load information. Feel free to PR that addition :)
Will be fixed in next release (#2013)
Most helpful comment
Will be fixed in next release (#2013)