-
Notifications
You must be signed in to change notification settings - Fork 361
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels