Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel Scout issue in initializeQueryUsingScout implementation #1188

Closed
nunomaduro opened this issue Jan 3, 2019 · 1 comment
Closed

Laravel Scout issue in initializeQueryUsingScout implementation #1188

nunomaduro opened this issue Jan 3, 2019 · 1 comment

Comments

@nunomaduro
Copy link
Member

nunomaduro commented Jan 3, 2019

  • Laravel Version: 5.7.19
  • Nova Version: 1.2.1
  • PHP Version: 7.3

Description:

The current implementation of the method PerformsQueries::initializeQueryUsingScout assumes that the method Searchable::getScoutKey always returns getKey. So when you run scout:import, normally, objectID at Algolia will be 1, 2, etc.

The problem is Searchable::getScoutKey method can be actually override by the developer, returning something else, like App\Model::1. Each leads to a search with no results.

The solution is get models instances from the scout search, and using the getKey to get models keys:

    protected static function initializeQueryUsingScout(NovaRequest $request, $query, $search, $withTrashed)
    {
        $keys = tap(static::applySoftDeleteConstraint(
            static::newModel()->search($search), $withTrashed
        ), function ($scoutBuilder) use ($request) {
            static::scoutQuery($request, $scoutBuilder);
-       })->take(200)->keys();
+        })->take(200)->get()->map->getKey();

        return static::applySoftDeleteConstraint(
            $query->whereIn(static::newModel()->getQualifiedKeyName(), $keys->all()), $withTrashed
        );
    }
@nunomaduro nunomaduro changed the title Issue with initializeQueryUsingScout implementation Laravel Scout issue in initializeQueryUsingScout implementation Jan 7, 2019
@bonzai
Copy link

bonzai commented Jan 9, 2019

This has been fixed and will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants