Skip to content

ParseQuery::equalTo with strange behavior #476

Closed
@igor-mobapps

Description

@igor-mobapps

Issue Description

Hello, I currently have a use case that requires making 2 conditions in the same field but with different values.

However, when using equalTo(field, value) and then notEqualTo(field, value) it returns a warning

Message: Warning: Illegal string offset '$ne'

This happens because when trying to add the $ne condition to the $this->where in the ParseQuery::addCondition($key, $condition, $value) method, the $this->where[$key] is a string, due to the ParseQuery::equalTo($key, $value) method adding the value directly to the $this->where array

equalto01

Steps to reproduce

$query = new ParseQuery('SomeClass');
$query->equalTo('docs.situation', 'pending');
$query->notEqualTo('docs.situation', 'rejected'); -> throw an warning and query break

Note: If the equalTo query is the last one to be called, it overrides the previous condition

$query = new ParseQuery('SomeClass');
$query->notEqualTo('docs.situation', 'rejected'); // is not added to the where stack
$query->lessThan('docs.situation', 'rejected'); // is not added to the where stack
$query->greaterThan('docs.situation', 'rejected'); // is not added to the where stack
$query->equalTo('docs.situation', 'pending');

Note: the code above is just a use case, of course the query itself doesn’t make much sense

Result of the query structure above

Parse\ParseQuery Object
(
    [className:Parse\ParseQuery:private] => Taxista
    [where:Parse\ParseQuery:private] => Array
        (
            [docs.situation] => pending
        )

    [orderBy:Parse\ParseQuery:private] => Array
        (
        )

    [includes:Parse\ParseQuery:private] => Array
        (
        )

    [excludes:Parse\ParseQuery:private] => Array
        (
        )

    [selectedKeys:Parse\ParseQuery:private] => Array
        (
        )

    [skip:Parse\ParseQuery:private] => 0
    [count:Parse\ParseQuery:private] => 
    [limit:Parse\ParseQuery:private] => -1
    [readPreference:Parse\ParseQuery:private] => 
    [includeReadPreference:Parse\ParseQuery:private] => 
    [subqueryReadPreference:Parse\ParseQuery:private] => 
)

Solution

Instead of using $this->where[$key] inside the ParseQuery::equalTo() method, use the $this->addCondition($key, '$eq', $value) method.

equalto02

I don't know if there is any special reason for using $this->where directly in the ParseQuery::equalTo() method instead of using $this->addCondition($key, '$eq', $value), but with aggregation the query listed above works normally.

With aggregate

// it works
$query = new ParseQuery('SomeClass');
$query->aggregate([
    'match' => [
        'docs.situation' => [
            '$eq' => 'pending',
            '$ne' => 'rejected'
        ]
    ]
]);

Environment Details

  • Your PHP Version: 7.4
  • Your Parse PHP SDK Version: 1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions