@@ -106,11 +106,14 @@ public function getFresh($columns = array('*'))
106
106
107
107
foreach ($ this ->aggregate ['columns ' ] as $ column )
108
108
{
109
+ // Translate count into sum
109
110
if ($ function == 'count ' )
110
111
{
111
112
$ group [$ column ] = array ('$sum ' => 1 );
112
113
}
113
- else {
114
+ // Pass other functions directly
115
+ else
116
+ {
114
117
$ group [$ column ] = array ('$ ' . $ function => '$ ' . $ column );
115
118
}
116
119
}
@@ -160,7 +163,7 @@ public function getFresh($columns = array('*'))
160
163
}
161
164
162
165
/**
163
- * Generate the unique cache key for the query.
166
+ * Generate the unique cache key for the current query.
164
167
*
165
168
* @return string
166
169
*/
@@ -260,14 +263,21 @@ public function whereBetween($column, array $values, $boolean = 'and')
260
263
*/
261
264
public function insert (array $ values )
262
265
{
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 )
267
270
{
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
+ }
269
277
}
270
278
279
+ if (!$ batch ) $ values = array ($ values );
280
+
271
281
// Batch insert
272
282
return $ this ->collection ->batchInsert ($ values );
273
283
}
@@ -502,7 +512,7 @@ protected function compileWheres()
502
512
// The new list of compiled wheres
503
513
$ wheres = array ();
504
514
505
- foreach ($ this ->wheres as $ i=> &$ where )
515
+ foreach ($ this ->wheres as $ i => &$ where )
506
516
{
507
517
// Convert id's
508
518
if (isset ($ where ['column ' ]) && $ where ['column ' ] == '_id ' )
0 commit comments