@@ -106,11 +106,14 @@ public function getFresh($columns = array('*'))
106106
107107 foreach ($ this ->aggregate ['columns ' ] as $ column )
108108 {
109+ // Translate count into sum
109110 if ($ function == 'count ' )
110111 {
111112 $ group [$ column ] = array ('$sum ' => 1 );
112113 }
113- else {
114+ // Pass other functions directly
115+ else
116+ {
114117 $ group [$ column ] = array ('$ ' . $ function => '$ ' . $ column );
115118 }
116119 }
@@ -160,7 +163,7 @@ public function getFresh($columns = array('*'))
160163 }
161164
162165 /**
163- * Generate the unique cache key for the query.
166+ * Generate the unique cache key for the current query.
164167 *
165168 * @return string
166169 */
@@ -260,14 +263,21 @@ public function whereBetween($column, array $values, $boolean = 'and')
260263 */
261264 public function insert (array $ values )
262265 {
263- // Since every insert gets treated like a batch insert, we will make sure the
264- // bindings are structured in a way that is convenient for building these
265- // inserts statements by verifying the elements are actually an array.
266- if ( ! is_array ( reset ( $ values )) )
266+ // Since every insert gets treated like a batch insert, we will have to detect
267+ // if the user is inserting a single document or an array of documents.
268+ $ batch = true ;
269+ foreach ( $ values as $ value )
267270 {
268- $ values = array ($ values );
271+ // As soon as we find a value that is not an array we assume the user is
272+ // inserting a single document.
273+ if (!is_array ($ value ))
274+ {
275+ $ batch = false ; break ;
276+ }
269277 }
270278
279+ if (!$ batch ) $ values = array ($ values );
280+
271281 // Batch insert
272282 return $ this ->collection ->batchInsert ($ values );
273283 }
@@ -502,7 +512,7 @@ protected function compileWheres()
502512 // The new list of compiled wheres
503513 $ wheres = array ();
504514
505- foreach ($ this ->wheres as $ i=> &$ where )
515+ foreach ($ this ->wheres as $ i => &$ where )
506516 {
507517 // Convert id's
508518 if (isset ($ where ['column ' ]) && $ where ['column ' ] == '_id ' )
0 commit comments