6
6
use DateTime ;
7
7
use Closure ;
8
8
9
+ use Illuminate \Database \Query \Builder as QueryBuilder ;
9
10
use Illuminate \Database \Query \Expression ;
10
11
use Jenssegers \Mongodb \Connection ;
11
12
12
- class Builder extends \ Illuminate \ Database \ Query \Builder {
13
+ class Builder extends QueryBuilder {
13
14
14
15
/**
15
16
* The database collection
@@ -193,6 +194,7 @@ public function getFresh($columns = array())
193
194
foreach ($ this ->columns as $ column )
194
195
{
195
196
$ key = str_replace ('. ' , '_ ' , $ column );
197
+
196
198
$ group [$ key ] = array ('$last ' => '$ ' . $ column );
197
199
}
198
200
}
@@ -374,17 +376,18 @@ public function insert(array $values)
374
376
// Since every insert gets treated like a batch insert, we will have to detect
375
377
// if the user is inserting a single document or an array of documents.
376
378
$ batch = true ;
379
+
377
380
foreach ($ values as $ value )
378
381
{
379
382
// As soon as we find a value that is not an array we assume the user is
380
383
// inserting a single document.
381
- if (! is_array ($ value ))
384
+ if ( ! is_array ($ value ))
382
385
{
383
386
$ batch = false ; break ;
384
387
}
385
388
}
386
389
387
- if (! $ batch ) $ values = array ($ values );
390
+ if ( ! $ batch ) $ values = array ($ values );
388
391
389
392
// Batch insert
390
393
$ result = $ this ->collection ->batchInsert ($ values );
@@ -405,7 +408,7 @@ public function insertGetId(array $values, $sequence = null)
405
408
406
409
if (1 == (int ) $ result ['ok ' ])
407
410
{
408
- if (! $ sequence )
411
+ if (is_null ( $ sequence) )
409
412
{
410
413
$ sequence = '_id ' ;
411
414
}
@@ -454,6 +457,7 @@ public function increment($column, $amount = 1, array $extra = array(), array $o
454
457
$ this ->where (function ($ query ) use ($ column )
455
458
{
456
459
$ query ->where ($ column , 'exists ' , false );
460
+
457
461
$ query ->orWhereNotNull ($ column );
458
462
});
459
463
@@ -502,6 +506,7 @@ public function pluck($column)
502
506
public function delete ($ id = null )
503
507
{
504
508
$ wheres = $ this ->compileWheres ();
509
+
505
510
$ result = $ this ->collection ->remove ($ wheres );
506
511
507
512
if (1 == (int ) $ result ['ok ' ])
@@ -577,13 +582,13 @@ public function push($column, $value = null, $unique = false)
577
582
$ operator = $ unique ? '$addToSet ' : '$push ' ;
578
583
579
584
// Check if we are pushing multiple values.
580
- $ multipleValues = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
585
+ $ batch = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
581
586
582
587
if (is_array ($ column ))
583
588
{
584
589
$ query = array ($ operator => $ column );
585
590
}
586
- else if ($ multipleValues )
591
+ else if ($ batch )
587
592
{
588
593
$ query = array ($ operator => array ($ column => array ('$each ' => $ value )));
589
594
}
@@ -605,10 +610,10 @@ public function push($column, $value = null, $unique = false)
605
610
public function pull ($ column , $ value = null )
606
611
{
607
612
// Check if we passed an associative array.
608
- $ multipleValues = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
613
+ $ batch = (is_array ($ value ) and array_keys ($ value ) === range (0 , count ($ value ) - 1 ));
609
614
610
615
// If we are pulling multiple values, we need to use $pullAll.
611
- $ operator = $ multipleValues ? '$pullAll ' : '$pull ' ;
616
+ $ operator = $ batch ? '$pullAll ' : '$pull ' ;
612
617
613
618
if (is_array ($ column ))
614
619
{
0 commit comments