File tree Expand file tree Collapse file tree 1 file changed +2
-16
lines changed
src/Jenssegers/Mongodb/Eloquent Expand file tree Collapse file tree 1 file changed +2
-16
lines changed Original file line number Diff line number Diff line change @@ -215,34 +215,20 @@ public function raw($expression = null)
215
215
// Get raw results from the query builder.
216
216
$ results = $ this ->query ->raw ($ expression );
217
217
218
- $ connection = $ this ->model ->getConnectionName ();
219
-
220
218
// Convert MongoCursor results to a collection of models.
221
219
if ($ results instanceof MongoCursor)
222
220
{
223
221
$ results = iterator_to_array ($ results , false );
224
222
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 );
238
224
}
239
225
240
226
// The result is a single object.
241
227
else if (is_array ($ results ) and array_key_exists ('_id ' , $ results ))
242
228
{
243
229
$ model = $ this ->model ->newFromBuilder ($ results );
244
230
245
- $ model ->setConnection ($ connection );
231
+ $ model ->setConnection ($ this -> model -> getConnection () );
246
232
247
233
return $ model ;
248
234
}
You can’t perform that action at this time.
0 commit comments