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

Commit 9389443

Browse files
authored
Merge pull request #209 from ferpetrelli/master
Use getScoutKey instead of getKey to get the ID field
2 parents 941aee0 + b26b9b6 commit 9389443

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/Indexers/BulkIndexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function update(Collection $models)
4343
}
4444

4545
$actionPayload = (new RawPayload())
46-
->set('index._id', $model->getKey());
46+
->set('index._id', $model->getScoutKey());
4747

4848
$bulkPayload
4949
->add('body', $actionPayload->get())
@@ -64,7 +64,7 @@ public function delete(Collection $models)
6464

6565
$models->each(function ($model) use ($bulkPayload) {
6666
$actionPayload = (new RawPayload())
67-
->set('delete._id', $model->getKey());
67+
->set('delete._id', $model->getScoutKey());
6868

6969
$bulkPayload->add('body', $actionPayload->get());
7070
});

src/Payloads/DocumentPayload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DocumentPayload extends TypePayload
1616
*/
1717
public function __construct(Model $model)
1818
{
19-
if ($model->getKey() === null) {
19+
if ($model->getScoutKey() === null) {
2020
throw new Exception(sprintf(
2121
'The key value must be set to construct a payload for the %s instance.',
2222
get_class($model)
@@ -25,7 +25,7 @@ public function __construct(Model $model)
2525

2626
parent::__construct($model);
2727

28-
$this->payload['id'] = $model->getKey();
28+
$this->payload['id'] = $model->getScoutKey();
2929
$this->protectedKeys[] = 'id';
3030
}
3131
}

tests/Dependencies/Model.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function mockModel(array $params = [])
1919
$params['methods'] ?? [],
2020
[
2121
'getKey',
22+
'getScoutKey',
2223
'trashed',
2324
'searchableAs',
2425
'toSearchableArray',
@@ -35,6 +36,10 @@ public function mockModel(array $params = [])
3536
->method('getKey')
3637
->willReturn($params['key'] ?? 1);
3738

39+
$mock
40+
->method('getScoutKey')
41+
->willReturn($params['key'] ?? 1);
42+
3843
$mock
3944
->method('trashed')
4045
->willReturn($params['trashed'] ?? false);

0 commit comments

Comments
 (0)