Open hamidmayeli opened 1 year ago
First, only objects are supported and second, if you want to filter based and category having a specific ID.
then you can create categories as separate objects
and link them to business objects like
{ "business": [ { "id": 2, "rate": 5, "logo": "https://loremflickr.com/640/480?lock=6423556804050944", "email": "klalh35@gmail.com", "telephone": "021 178 03 73" } ], "categories": [ { "id": 1, "name": "cat 1", "businessId": 1 }, { "id": 2, "name": "cat 2", "businessId": 2 } ] }
now you can get categories
http://localhost:3000/categories?id=2
and you can also get specific business object
http://localhost:3000/categories?businessId=1
Given the following data:
[ { "id": 2, "rate": 5, "logo": "https://loremflickr.com/640/480?lock=6423556804050944", "email": "klalh35@gmail.com", "telephone": "021 178 03 73", "categories": [ { "id": 1, "name": "cat 1" }, { "id": 2, "name": "cat 2" } ] } ]
Is it possible to filter based and category having a specific id.
I have tried
http://localhost:4000/business?categories.id=10
and it didn't work.
The reason your query http://localhost:4000/business?categories.id=10 didn't work is that json-server doesn't support filtering by properties of nested objects or arrays, like the categories array in your data, using its default query parameters. It only supports filtering on top-level fields directly.
Given the following data:
Is it possible to filter based and category having a specific id.
I have tried
http://localhost:4000/business?categories.id=10
and it didn't work.