Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 6f19513

Browse files
committed
getScoutKeyName must return field name without table prefix
1 parent 9389443 commit 6f19513

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/ElasticEngine.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,24 +295,24 @@ public function map(Builder $builder, $results, $model)
295295
return Collection::make();
296296
}
297297

298-
$primaryKey = $model->getKeyName();
298+
$scoutKeyName = $model->getScoutKeyName();
299299

300300
$columns = Arr::get($results, '_payload.body._source');
301301

302302
if (is_null($columns)) {
303303
$columns = ['*'];
304304
} else {
305-
$columns[] = $primaryKey;
305+
$columns[] = $scoutKeyName;
306306
}
307307

308308
$ids = $this->mapIds($results)->all();
309309

310310
$query = $model::usesSoftDelete() ? $model->withTrashed() : $model->newQuery();
311311

312312
$models = $query
313-
->whereIn($primaryKey, $ids)
313+
->whereIn($scoutKeyName, $ids)
314314
->get($columns)
315-
->keyBy($primaryKey);
315+
->keyBy($scoutKeyName);
316316

317317
return Collection::make($results['hits']['hits'])
318318
->map(function ($hit) use ($models) {
@@ -348,7 +348,7 @@ public function flush($model)
348348
$query = $model::usesSoftDelete() ? $model->withTrashed() : $model->newQuery();
349349

350350
$query
351-
->orderBy($model->getKeyName())
351+
->orderBy($model->getScoutKeyName())
352352
->unsearchable();
353353
}
354354
}

src/Searchable.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
use Illuminate\Support\Arr;
77
use ScoutElastic\Builders\FilterBuilder;
88
use ScoutElastic\Builders\SearchBuilder;
9-
use Laravel\Scout\Searchable as ScoutSearchable;
9+
use Laravel\Scout\Searchable as SourceSearchable;
1010

1111
trait Searchable
1212
{
13-
use ScoutSearchable {
14-
ScoutSearchable::bootSearchable as bootScoutSearchable;
13+
use SourceSearchable {
14+
SourceSearchable::bootSearchable as sourceBootSearchable;
15+
SourceSearchable::getScoutKeyName as sourceGetScoutKeyName;
1516
}
1617

1718
/**
@@ -34,7 +35,7 @@ public static function bootSearchable()
3435
return;
3536
}
3637

37-
self::bootScoutSearchable();
38+
self::sourceBootSearchable();
3839

3940
self::$isSearchableTraitBooted = true;
4041
}
@@ -49,8 +50,8 @@ public function getIndexConfigurator()
4950
{
5051
static $indexConfigurator;
5152

52-
if (! $indexConfigurator) {
53-
if (! isset($this->indexConfigurator) || empty($this->indexConfigurator)) {
53+
if (!$indexConfigurator) {
54+
if (!isset($this->indexConfigurator) || empty($this->indexConfigurator)) {
5455
throw new Exception(sprintf(
5556
'An index configurator for the %s model is not specified.',
5657
__CLASS__
@@ -143,4 +144,14 @@ public function getHighlightAttribute()
143144
{
144145
return $this->highlight;
145146
}
147+
148+
/**
149+
* Get the key name used to index the model.
150+
*
151+
* @return mixed
152+
*/
153+
public function getScoutKeyName()
154+
{
155+
return $this->getKeyName();
156+
}
146157
}

0 commit comments

Comments
 (0)