Open romainPrignon opened 8 years ago
The date
field is string in your db. In request params its being parsed as number.
If the db is like:
{
"vehicles": [
{
"label": "renault megane",
"brand": "RENAULT",
"model": "MEGANE III",
"date": 201207
}
]
}
then the request is working fine
http://localhost:4000/vehicles?date=201207
But there must be some solution to keep numbers as string in db.
your are right. I tried "http://localhost:4000/vehicles?date=201207" with :
{
"vehicles": [
{
"label": "renault megane",
"brand": "RENAULT",
"model": "MEGANE III",
"date": 201207
}
]
}
and it worked. But :
"date": "201207"
do not work. I'm going to check why this is jappening
Thanks for your solution !
@gagan-bansal thank you for the explanation
@romainPrignon json-server automatically tries to convert query parameters, so if you have ?some_boolean=true&some_integer=1
they will be converted: "true" -> true
and "1" -> 1
. This allows to use native types other than strings in databases. If it can't convert a string to an integer it will keep the string though.
@typicode thanks for detailed explanation. How would this case be resolved many times ids are number but stored as string like `001'?
return _.matchesProperty(key, value)(element)||_.matchesProperty(key,originValue)(element);
just change the code in the plural.js . i solve my problem ..
Hi,
I wonder if i'm doing something wrong It's seems that I can't filter on a specific field
When I go to http://localhost:4000/vehicles?date=24/08/2008
I got the data in response but when
http://localhost:4000/vehicles?date_gte=23/08/2008&date_lte=25/08/2008 i got []
my object is like { "athlete": "Natalie Coughlin", "age": 25, "country": "United States", "year": 2008, "date": "24/08/2008", "sport": "Swimming", "gold": 1, "silver": 2, "bronze": 3, "total": 6 }
Just try storing date as 'YYYY/DD/MM', though I have not tested but in general this is the way date is store as string for sorting purpose.
Hi,
I wonder if i'm doing something wrong It's seems that I can't filter on a specific field
When I go to http://localhost:4000/vehicles?date=201207
I got
But when I go to http://localhost:4000/vehicles?brand=RENAULT
I got
this is my fixtures.json file:
and I launch the server with : json-server -w -q -p 4000 -d 100 fixtures.json