Skip to content

Commit 40e719d

Browse files
committed
fix ignore
1 parent 2a8df1c commit 40e719d

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/Query.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ public function query()
751751
$query["type"] = $this->getType();
752752
}
753753

754-
if($this->model && $this->useGlobalScopes){
754+
if ($this->model && $this->useGlobalScopes) {
755755
$this->model->boot($this);
756756
}
757757

@@ -922,32 +922,36 @@ protected function getAll($result = [])
922922

923923
$new = [];
924924

925-
foreach ($result["hits"]["hits"] as $row) {
925+
if (array_key_exists("hits", $result)) {
926926

927-
$model = $this->model ? new $this->model($row["_source"], true) : new Model($row["_source"], true);
927+
foreach ($result["hits"]["hits"] as $row) {
928928

929-
$model->setConnection($model->getConnection());
930-
$model->setIndex($row["_index"]);
931-
$model->setType($row["_type"]);
929+
$model = $this->model ? new $this->model($row["_source"], true) : new Model($row["_source"], true);
932930

933-
// match earlier version
931+
$model->setConnection($model->getConnection());
932+
$model->setIndex($row["_index"]);
933+
$model->setType($row["_type"]);
934934

935-
$model->_index = $row["_index"];
936-
$model->_type = $row["_type"];
937-
$model->_id = $row["_id"];
938-
$model->_score = $row["_score"];
935+
// match earlier version
939936

940-
$new[] = $model;
941-
}
937+
$model->_index = $row["_index"];
938+
$model->_type = $row["_type"];
939+
$model->_id = $row["_id"];
940+
$model->_score = $row["_score"];
941+
942+
$new[] = $model;
943+
}
944+
945+
$new = new Collection($new);
942946

943-
$new = new Collection($new);
947+
$new->total = $result["hits"]["total"];
948+
$new->max_score = $result["hits"]["max_score"];
949+
$new->took = $result["took"];
950+
$new->timed_out = $result["timed_out"];
951+
$new->scroll_id = isset($result["_scroll_id"]) ? $result["_scroll_id"] : NULL;
952+
$new->shards = (object)$result["_shards"];
944953

945-
$new->total = $result["hits"]["total"];
946-
$new->max_score = $result["hits"]["max_score"];
947-
$new->took = $result["took"];
948-
$new->timed_out = $result["timed_out"];
949-
$new->scroll_id = isset($result["_scroll_id"]) ? $result["_scroll_id"] : NULL;
950-
$new->shards = (object)$result["_shards"];
954+
}
951955

952956
return $new;
953957
}
@@ -960,9 +964,9 @@ protected function getAll($result = [])
960964
protected function getFirst($result = [])
961965
{
962966

963-
$data = $result["hits"]["hits"];
967+
if (array_key_exists("hits", $result) && count($result["hits"]["hits"])) {
964968

965-
if (count($data)) {
969+
$data = $result["hits"]["hits"];
966970

967971
if ($this->model) {
968972
$model = new $this->model($data[0]["_source"], true);
@@ -1393,7 +1397,8 @@ function __call($method, $parameters)
13931397
/**
13941398
* @return $this
13951399
*/
1396-
public function withoutGlobalScopes(){
1400+
public function withoutGlobalScopes()
1401+
{
13971402

13981403
$this->useGlobalScopes = false;
13991404

0 commit comments

Comments
 (0)