Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Parse/ParseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,27 @@ public function get($objectId, $useMasterKey = false)
*/
public function equalTo($key, $value)
{
$this->addCondition($key, '$eq', $value);
$encodedValue = ParseClient::_encode($value, true);
if (!isset($this->where[$key])) {
$this->where[$key] = $encodedValue;
} else {
$isConditionMap = false;
if (is_array($this->where[$key])) {
foreach ($this->where[$key] as $conditionKey => $_) {
if (is_string($conditionKey) && str_starts_with($conditionKey, '$')) {
$isConditionMap = true;
break;
}
}
}

if (!$isConditionMap) {
$this->where[$key] = [
'$eq' => $this->where[$key],
];
}
$this->where[$key]['$eq'] = $encodedValue;
}

return $this;
}
Expand Down
54 changes: 48 additions & 6 deletions tests/Parse/ParseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2663,9 +2663,7 @@ public function testGetAndSetConditions()

$this->assertEquals([
'where' => [
'key' => [
'$eq' => 'value',
],
'key' => 'value',
'key2' => [
'$ne' => 'value2',
],
Expand Down Expand Up @@ -2695,6 +2693,52 @@ public function testGetAndSetConditions()
);
}

/**
* @group query-equalTo-conditions
*/
public function testEqualToObjectUsesDirectEqualityForArrayMembershipQueries()
{
$object = new ParseObject('TestObject', 'testObjectId');

$query = new ParseQuery('TestObject');
$query->equalTo('items', $object);

$this->assertSame([
'where' => [
'items' => [
'__type' => 'Pointer',
'className' => 'TestObject',
'objectId' => 'testObjectId',
],
],
], $query->_getOptions());
}

/**
* @group query-equalTo-conditions
*/
public function testEqualToWithRepeatedSameKeyConvertsDirectEqualityToConditionMap()
{
$firstObject = new ParseObject('TestObject', 'firstObjectId');
$secondObject = new ParseObject('TestObject', 'secondObjectId');

$query = new ParseQuery('TestObject');
$query->equalTo('items', $firstObject);
$query->equalTo('items', $secondObject);

$this->assertSame([
'where' => [
'items' => [
'$eq' => [
'__type' => 'Pointer',
'className' => 'TestObject',
'objectId' => 'secondObjectId',
],
],
],
], $query->_getOptions());
}

/**
* @group query-count-conditions
*/
Expand Down Expand Up @@ -2726,9 +2770,7 @@ public function testCountDoesNotOverrideConditions()

$this->assertSame([
'where' => [
'country' => [
'$eq' => 'US'
]
'country' => 'US'
],
'limit' => 1,
], $query->_getOptions());
Expand Down