zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

RestAPI only returning first result when passing in multiple filters example: user?filter[id]=2,1 #1573

Closed sw34 closed 2 months ago

sw34 commented 3 months ago

Description and expected behavior

According to the RestAPI documentation passing in a list of for example id's separated by comma's should return a list not just one result. Currently its only returning the record based on the id of the first number passed in.

I am modeling a new app based off your react-admin blog article https://zenstack.dev/blog/react-admin

Using the code in the linked Github repository I performed the following to recreate the issue:

  1. added a second user
  2. created two Post's, one tagged to each user
  3. refresh the Posts page and only one User shows in the User column (the first Post only) image

calling http://localhost:3000/api/model/user?filter[id]=2,1 only results in one record being returned (id = 2)

{
    "jsonapi": {
        "version": "1.1"
    },
    "links": {
        "self": "http://localhost:3000/user",
        "first": "http://localhost:3000/user?filter%5Bid%5D=2%2C1&page%5Blimit%5D=100",
        "last": "http://localhost:3000/user?filter%5Bid%5D=2%2C1&page%5Boffset%5D=0",
        "prev": null,
        "next": null
    },
    "data": [
        {
            "type": "user",
            "id": 2,
            "attributes": {
                "createdAt": "2024-07-10T21:05:26.915Z",
                "updatedAt": "2024-07-10T21:05:26.915Z",
                "email": "s@s.com",
                "name": "Test 1",
                "role": "Author"
            },
            "relationships": {
                "posts": {
                    "data": [
                        {
                            "type": "post",
                            "id": 1
                        }
                    ],
                    "links": {
                        "self": "http://localhost:3000/user/2/relationships/posts",
                        "related": "http://localhost:3000/user/2/posts"
                    }
                }
            },
            "links": {
                "self": "http://localhost:3000/user/2"
            }
        }
    ],
    "meta": {
        "serialization": {
            "values": {
                "data.0.attributes.createdAt": [
                    "Date"
                ],
                "data.0.attributes.updatedAt": [
                    "Date"
                ]
            }
        },
        "total": 1
    }
}

Environment (please complete the following information):

Additional context Add any other context about the problem here.

ymc9 commented 2 months ago

Thanks for reporting this @sw34 . The comma-separated filtering is actually not implemented. I'll make a fix and include it in the upcoming release.