Open Tzal3x opened 4 months ago
It should be possible to be able to find the entries of another entity by using the foreign key.
For example let's say we have two entities: users and companies.
users
companies
Each users entry has a companyId.
companyId
The json server should be able to fetch all the users of a company.
i.e.
Given the following db.json :
db.json
{ "users": [ { "id": "23", "firstName": "Bill", "age": 20, "companyId": "1" }, { "id": "40", "firstName": "Alex", "age": 40, "companyId": "2" }, { "id": "41", "firstName": "Nick", "age": 40, "companyId": "2" } ], "companies": [ { "id": "1", "name": "Apple", "description": "iphone" }, { "id": "2", "name": "Google", "description": "search" } ] }
Running the server with npx json-server db.json
npx json-server db.json
curl http://localhost:3000/companies/2/users
[ { "id": "40", "firstName": "Alex", "age": 40, "companyId": "2" }, { "id": "41", "firstName": "Nick", "age": 40, "companyId": "2" } ]
$ curl http://localhost:3000/companies/2/users
Not Found
Funny. I'm using json-server v0.17.4 with node v20 and works fine with the data you provided?
It should be possible to be able to find the entries of another entity by using the foreign key.
For example let's say we have two entities:
users
andcompanies
.Each
users
entry has acompanyId
.The json server should be able to fetch all the users of a company.
i.e.
Given the following
db.json
:Running the server with
npx json-server db.json
Expected behavior
Actual behavior