Skip to content

Commit

Permalink
Fix issues for users providing searchable array without primary key (l…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmachatschek authored Nov 11, 2021
1 parent ad96177 commit 5e7a5db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Engines/MeiliSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function update($models)
return;
}

return array_merge($searchableData, $model->scoutMetadata());
return array_merge(
[$model->getKeyName() => $model->getScoutKey()],
$searchableData,
$model->scoutMetadata()
);
})->filter()->values()->all();

if (! empty($objects)) {
Expand Down
6 changes: 4 additions & 2 deletions tests/Unit/MeiliSearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ public function test_a_model_is_indexed_with_a_custom_meilisearch_key()
{
$client = m::mock(Client::class);
$client->shouldReceive('index')->with('table')->andReturn($index = m::mock(Indexes::class));
$index->shouldReceive('addDocuments')->with([['id' => 'my-meilisearch-key.1']], 'id');
$index->shouldReceive('addDocuments')->once()->with([[
'id' => 5,
]], 'id');

$engine = new MeiliSearchEngine($client);
$engine->update(Collection::make([new MeiliSearchCustomKeySearchableModel()]));
$engine->update(Collection::make([new MeiliSearchCustomKeySearchableModel(['id' => 5])]));
}

public function test_flush_a_model_with_a_custom_meilisearch_key()
Expand Down

0 comments on commit 5e7a5db

Please sign in to comment.