laravel / scout

Laravel Scout provides a driver based solution to searching your Eloquent models.
https://laravel.com/docs/scout
MIT License
1.55k stars 330 forks source link

[10.x] Get the key name through getScoutKeyName() on the Database engine #843

Closed antonioribeiro closed 3 months ago

antonioribeiro commented 3 months ago

I'm not sure why the database engine is the only still using getKeyName(), but it should be using getScoutKeyName() as all the others. I just found this while trying to set a custom ID for my searches other than the one I'm using for normal usage of the searchable model.

While trying to join a table:

Post::search($search)
    ->query(function ($query) {
        ...

        $query->join('twill_blocks', 'posts.id', '=', 'twill_blocks.blockable_id');
    })
    ->get();

Scout was raising a Column 'id' in order clause is ambiguous caused by an unqualified order by id that was not possible to customize as the only way would be by overloading getKeyName() and that would break how things work for my Post model out of the search context.