parse-community / parse-php-sdk

The PHP SDK for Parse Platform
https://parseplatform.org/
Other
812 stars 346 forks source link

Queries on array values broken since 2.3.1 #516

Open eskil-booli opened 1 year ago

eskil-booli commented 1 year ago

New Issue Checklist

We're not running the latest Parse server version, hence I haven't checked the last item above.

Issue Description

The fix for equalTo in 2.3.1 broke queries on array values.

Steps to reproduce

For example, to fetch all roles for a specific user:

$query = ParseUser::query();
$parseUser = $query->get("someUserId", true);
$query = ParseRole::query();
$query->equalTo("users", $parseUser);
$parseRoles = $query->find(true);

Actual Outcome

In previous versions, the query sent to Parse would look like:

{
  "users": {
    "__type": "Pointer",
    "className": "_User",
    "objectId": "someUserId"
  }
}

Which would give us the roles for that user back.

Expected Outcome

In 2.3.1 the query became:

{
  "where": {
    "users": {
      "$eq": {
        "__type": "Pointer",
        "className": "_User",
        "objectId":"someUserId"
      }
    }
  }
}

Which does not give any roles back. users on _Role is an array with a single user in our case.

Environment

Parse PHP SDK

Server

Database

parse-github-assistant[bot] commented 1 year ago

Thanks for opening this issue!

zeliard91 commented 1 year ago

Hi,

For information, the same bug is also affecting queries on Relations when trying to fetch records from the inversed side of the relationship with a recent version of the server.

// suppose we have a author object, for which we want to get all books
$author = ...

// first we will create a query on the Book object
$query = new ParseQuery("Book");

// now we will query the authors relation to see if the author object we have
// is contained therein
$query->equalTo("authors", $author);

The SDK is sending a "where authors $eq: {}" instead of "authors: {}"

Environment

Parse PHP SDK

Server

Database

dplewis commented 1 year ago

We could revert https://github.com/parse-community/parse-php-sdk/pull/510 back. Can you write a failing test? We might have to do a server fix.