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)
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 }
You can’t perform that action at this time.
0 commit comments