Scout Version
10.23.0
Scout Driver
Meilisearch
Laravel Version
12.38.1
PHP Version
8.2
Database Driver & Version
MySQL 8.0 via Laravel Sail
SDK Version
1.16.1
Meilisearch CLI Version
No response
Description
Problem
getScoutKeyName() is currently used in two different contexts:
- Field name in search index (Meilisearch, Algolia)
- Column name in database queries (SQL)
This causes failures when a model needs different names for each context.
Why this matters
Consider two models indexed together:
| Model |
Database PK |
Index field |
User |
id (int) |
id |
Invitation |
uuid (string) |
id |
Both models have id field in Meilisearch, but in database it's id or uuid depending on the model. This is where it breaks - getScoutKeyName() cannot
return both id (for index) and uuid (for database) at the same time.
Affected code
| Location |
Uses getScoutKeyName() for |
MeilisearchEngine::update() |
Index field name ✓ |
SearchableScope::searchable() |
chunkById() column ✗ |
Searchable::queryScoutModelsByIds() |
whereIn() column ✗ |
QueueImportCommand::handle() |
min()/max() column ✗ |
DatabaseEngine::searchModels() |
orderBy() column ✗ |
Steps To Reproduce
- Create two models with different primary keys:
// User.php - standard id
class User extends Model
{
use Searchable;
protected $primaryKey = 'id';
}
// Invitation.php - uuid primary key
class Invitation extends Model
{
use Searchable;
protected $primaryKey = 'uuid';
protected $keyType = 'string';
public function getScoutKeyName()
{
return 'id'; // Need 'id' in Meilisearch
}
public function getScoutKey()
{
return $this->uuid;
}
public function toSearchableArray()
{
return [
'id' => $this->uuid, // Map uuid to 'id' field
// ...
];
}
}
- Run import:
php artisan scout:import "App\Models\Invitation"
- Result:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause'
The chunkById() uses getScoutKeyName() which returns id, but database column is uuid.
Scout Version
10.23.0
Scout Driver
Meilisearch
Laravel Version
12.38.1
PHP Version
8.2
Database Driver & Version
MySQL 8.0 via Laravel Sail
SDK Version
1.16.1
Meilisearch CLI Version
No response
Description
Problem
getScoutKeyName()is currently used in two different contexts:This causes failures when a model needs different names for each context.
Why this matters
Consider two models indexed together:
Userid(int)idInvitationuuid(string)idBoth models have
idfield in Meilisearch, but in database it'sidoruuiddepending on the model. This is where it breaks -getScoutKeyName()cannotreturn both
id(for index) anduuid(for database) at the same time.Affected code
getScoutKeyName()forMeilisearchEngine::update()SearchableScope::searchable()chunkById()column ✗Searchable::queryScoutModelsByIds()whereIn()column ✗QueueImportCommand::handle()min()/max()column ✗DatabaseEngine::searchModels()orderBy()column ✗Steps To Reproduce
php artisan scout:import "App\Models\Invitation"