cesardeazevedo / sails-hook-sequelize-blueprints

Sails blueprints for sequelize ORM
MIT License
32 stars 19 forks source link

where does not work #12

Open dzuluaga opened 8 years ago

dzuluaga commented 8 years ago

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 commented 8 years ago

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
cesardeazevedo commented 8 years ago

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.

dzuluaga commented 8 years ago

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.

loulin commented 8 years ago

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.