laravel-scout-elasticsearch icon indicating copy to clipboard operation
laravel-scout-elasticsearch copied to clipboard

[Feature] Question? MixedSearch - How to eager load realtionships and use pagination() at same time?

Open PitchRE opened this issue 2 years ago • 1 comments

      $data =   MixedSearch::search($request->q ?? '')->within(implode(',', $searchTypes))->query(function ($query) {
            $query->with('media');
        })->get();

I would like to eager load some relationship and use pagination. If I use paginate() with query(), it throws SQLSTATE[42000]: Syntax error or access violation.

SELECT count(*) AS aggregate FROM `mixed_search`.`php:20$20cs` WHERE `mixed_search`.`php:20$20cs`.`id` IN (7, 9, 4, 5)

PitchRE avatar Dec 19 '22 20:12 PitchRE

@PitchRE Did you try this approach to load relations? https://github.com/matchish/laravel-scout-elasticsearch#eager-load

matchish avatar Feb 01 '23 14:02 matchish