Filter by reference on array returns 400

I have…

  • [ ] Checked the logs and have provided the logs if I found something suspicious there

I’m submitting a…

  • [x] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [ ] Performance issue
  • [ ] Documentation issue or request

Current behavior

The API returns a 400 Bad Request when requesting a reference on an array.

GET https://cloud.squidex.io/api/content/asap-test/user?q={"filter":{"value": "uuid", "op": "eq", "path":"data.teams.iv.id"}}

{
    "message": "Validation error",
    "traceId": "|514f954-4d31e43605ecd09f.",
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "details": [
        "Json query not valid: Path 'data.teams.iv.id' does not point to a valid property in the model."
    ],
    "statusCode": 400
}

The user schema is:

{
    "properties": {},
    "scripts": {},
    "fieldsInLists": [],
    "fieldsInReferences": [],
    "fields": [
        {
            "name": "teams",
            "properties": {
                "fieldType": "Array"
            },
            "partitioning": "invariant",
            "nested": [
                {
                    "name": "id",
                    "properties": {
                        "fieldType": "References",
                        "editor": "List"
                    }
                }
            ]
        }
    ],
    "isPublished": true
}

I have an array of References because on my main code the relationship needs to have information associated with it.

Expected behavior

I have a self-hosted version for development that returns the a proper 200 response without errors.

Minimal reproduction of the problem

GET https://cloud.squidex.io/api/content/asap-test/user?q={"filter":{"value": "uuid", "op": "eq", "path":"data.teams.iv.id"}}

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Version: cloud

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:

Thank you very much for your good support request.

You can only filter things that are directly part of your content item. The id of the referenced item is not part of the item, but your reference field is basically and array of ids.

So you can use

{
   "filter":{
      "path":"data.teams.iv"
      "op":"eq",
      "value":"<MY-ID>"
   }
}

data.teams.iv is an array of ids, this is automatically translated to an contains query. So at least one of the values in the array must be the same as the id.

Thanks for the reply @Sebastian.
However if I take your suggestion I get a different error

GET https://cloud.squidex.io/api/content/asap-test/user?q={"filter":{"value": "f6e6c757-2f98-4322-ba1b-5741c4467a31", "op": "eq", "path":"data.teams.iv"}}
{
    "message": "Validation error",
    "traceId": "|5b6c5c08-415963c7a1db5111.",
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "details": [
        "Json query not valid: Unsupported type Array for data.teams.iv."
    ],
    "statusCode": 400
}

Notice that my reference is on a nested object.
I pasted a more complex example that it’s closer to my production environment:

{
    "properties": {},
    "scripts": {},
    "fieldsInLists": [],
    "fieldsInReferences": [],
    "fields": [
        {
            "name": "teams",
            "properties": {
                "fieldType": "Array"
            },
            "partitioning": "invariant",
            "nested": [
                {
                    "name": "id",
                    "properties": {
                        "isRequired": true,
                        "fieldType": "References",
                        "editor": "List",
                        "minItems": 1,
                        "maxItems": 1
                    }
                },
                {
                    "name": "role",
                    "properties": {
                        "fieldType": "String",
                        "editor": "Input",
                        "contentType": "Unspecified"
                    }
                }
            ]
        }
    ],
    "isPublished": true
}

Sorry, I have not realized that you are using nested items. Filtering on nesting objects is currently not possible.

There is a feature request for that. In general it would work like mentioned: