Skip to content

Commit f0b9105

Browse files
committed
Tweak raw()
1 parent a042c16 commit f0b9105

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/Jenssegers/Mongodb/Eloquent/Builder.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,34 +215,20 @@ public function raw($expression = null)
215215
// Get raw results from the query builder.
216216
$results = $this->query->raw($expression);
217217

218-
$connection = $this->model->getConnectionName();
219-
220218
// Convert MongoCursor results to a collection of models.
221219
if ($results instanceof MongoCursor)
222220
{
223221
$results = iterator_to_array($results, false);
224222

225-
$models = array();
226-
227-
// Once we have the results, we can spin through them and instantiate a fresh
228-
// model instance for each records we retrieved from the database. We will
229-
// also set the proper connection name for the model after we create it.
230-
foreach ($results as $result)
231-
{
232-
$models[] = $model = $this->model->newFromBuilder($result);
233-
234-
$model->setConnection($connection);
235-
}
236-
237-
return $this->model->newCollection($models);
223+
return $this->model->hydrate($results);
238224
}
239225

240226
// The result is a single object.
241227
else if (is_array($results) and array_key_exists('_id', $results))
242228
{
243229
$model = $this->model->newFromBuilder($results);
244230

245-
$model->setConnection($connection);
231+
$model->setConnection($this->model->getConnection());
246232

247233
return $model;
248234
}

0 commit comments

Comments
 (0)