sails-hook-sequelize-blueprints icon indicating copy to clipboard operation
sails-hook-sequelize-blueprints copied to clipboard

where does not work

Open dzuluaga opened this issue 10 years ago • 4 comments

Great hook. Pretty much everything worked except for find where clause. For instance, I tried to run the following API request and it returned a strage error:

GET /user?where={"name":{"contains":"Eri"}} HTTP/1.1
Host: localhost:1337

Error:

{
  "error@context": {}
}

Am I doing anything wrong? Thanks!

dzuluaga avatar Nov 30 '15 08:11 dzuluaga

I've just found the solution. Instead of using contain, which is the notation from Waterline. You need to stick to sequelize notation. Therefore, the search above should be translated into:

curl -G -X GET 'http://localhost:1337/user' --data-urlencode 'where={"name":{"$like":"%Eri%"}}' -v

dzuluaga avatar Dec 01 '15 00:12 dzuluaga

Interesting, it's related to the waterline / sequelize notation or something with this hook? i haven't tested with the where criteria object, only with http://localhost:1337/user?name=value&age=21,

thanks for the feedback.

cesardeazevedo avatar Dec 01 '15 00:12 cesardeazevedo

Correct, my confusion was that I was reading Sails.js Blueprint and I was using the exact Waterline notation to run "like" queries, and the response from the server wasn't helping to troubleshoot the issue. After I looked into the code in this line, I realized that it used sequelize model, which uses a sligthly different convention than waterline. I wonder that more users may have run into this issue and this could save them some time of debugging.

dzuluaga avatar Dec 01 '15 01:12 dzuluaga

Thanks @dzuluaga, it works by using sequelize combinations. By the way, the query string should be encoded like --data-urlencode, such as http://localhost:1337/user?where={"$or":[{"name":{"$like":"hello%25"}},{"id":2}]}, where %25 denotes to %, otherwise the where condition should not work.

loulin avatar Jan 04 '16 10:01 loulin