Skip to content

Commit

Permalink
Merge pull request #74 from designmynight/fix-save-after-index
Browse files Browse the repository at this point in the history
fix: perform ES queries on cloned model
  • Loading branch information
robbytaylor authored Jan 10, 2019
2 parents 5045e8f + bed526a commit 8ba82cd
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@ public function getSearchType()
*/
public function onSearchConnection(\Closure $callback)
{
$originalConnection = $this->getConnectionName();
$arguments = array_slice(func_get_args(), 1);

$this->setConnection(static::getElasticsearchConnectionName());
$elasticModel = clone $arguments[0];
$elasticModel->setConnectionName(static::getElasticsearchConnectionName());

try {
$result = $callback(...array_slice(func_get_args(), 1));
} finally {
$this->setConnection($originalConnection);
}
$arguments[0] = $elasticModel;

return $result;
return $callback(...$arguments);
}

/**
Expand Down

0 comments on commit 8ba82cd

Please sign in to comment.