Skip to content

Commit 7e8a9cc

Browse files
committed
Fix pull/push logic
1 parent bab6b2d commit 7e8a9cc

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,14 @@ public function push($column, $value = null, $unique = false)
515515
// Use the addToSet operator in case we only want unique items.
516516
$operator = $unique ? '$addToSet' : '$push';
517517

518+
// Check if we are pushing multiple values.
519+
$multipleValues = (is_array($value) and array_keys($value) === range(0, count($value) - 1));
520+
518521
if (is_array($column))
519522
{
520523
$query = array($operator => $column);
521524
}
522-
else if (is_array($value))
525+
else if ($multipleValues)
523526
{
524527
$query = array($operator => array($column => array('$each' => $value)));
525528
}
@@ -540,8 +543,13 @@ public function push($column, $value = null, $unique = false)
540543
*/
541544
public function pull($column, $value = null)
542545
{
546+
var_dump($value);
547+
548+
// Check if we passed an associative array.
549+
$multipleValues = (is_array($value) and array_keys($value) === range(0, count($value) - 1));
550+
543551
// If we are pulling multiple values, we need to use $pullAll.
544-
$operator = is_array($value) ? '$pullAll' : '$pull';
552+
$operator = $multipleValues ? '$pullAll' : '$pull';
545553

546554
if (is_array($column))
547555
{

0 commit comments

Comments
 (0)