diff --git a/src/Parse/ParseQuery.php b/src/Parse/ParseQuery.php index 2782995e..64a50561 100644 --- a/src/Parse/ParseQuery.php +++ b/src/Parse/ParseQuery.php @@ -140,7 +140,7 @@ public function get($objectId, $useMasterKey = false) */ public function equalTo($key, $value) { - $this->where[$key] = $value; + $this->addCondition($key, '$eq', $value); return $this; } diff --git a/tests/Parse/ParseQueryTest.php b/tests/Parse/ParseQueryTest.php index 30fc5a18..536971b1 100644 --- a/tests/Parse/ParseQueryTest.php +++ b/tests/Parse/ParseQueryTest.php @@ -2663,7 +2663,9 @@ public function testGetAndSetConditions() $this->assertEquals([ 'where' => [ - 'key' => 'value', + 'key' => [ + '$eq' => 'value', + ], 'key2' => [ '$ne' => 'value2', ], @@ -2719,4 +2721,57 @@ public function testUnknownCondition() 'unrecognized' => 1 ]); } + + /** + * @group query-equalTo-conditions + */ + public function testEqualToWithSameKeyDoesNotOverrideOtherConditions() + { + $baz = new ParseObject('TestObject'); + $baz->setArray('fooStack', [ + [ + 'status' => 'baz' + ], + [ + 'status' => 'bar' + ] + ]); + $baz->save(); + + $bar = new ParseObject('TestObject'); + $bar->setArray('fooStack', [ + [ + 'status' => 'bar' + ] + ]); + $bar->save(); + + $qux = new ParseObject('TestObject'); + $qux->setArray('fooStack', [ + [ + 'status' => 'bar', + ], + [ + 'status' => 'qux' + ] + ]); + $qux->save(); + + $query = new ParseQuery('TestObject'); + $query->notEqualTo('fooStack.status', 'baz'); + $query->equalTo('fooStack.status', 'bar'); + + $this->assertEquals(2, $query->count(true)); + + $this->assertSame([ + 'where' => [ + 'fooStack.status' => [ + '$ne' => 'baz', + '$eq' => 'bar', + ] + ], + 'limit' => 0, + 'count' => 1, + ], $query->_getOptions()); + } }