RyanQuey
RyanQuey

Reputation: 725

sails blueprints query in url not working

I have various GET http calls to my api with the following format:

/api/posts?userId=3

However, it is not filtering posts by its userId column, and just returns all posts, regardless of the posts' userId.

This syntax has worked in past projects I've had also, and is documented here. (The example they give is GET /purchase?amount=99.99).

Questions I've seen do not address the query language via defaults routes in this way, so I'm having trouble finding help. Any guesses on what could be going wrong?

UPDATE:

What does work as expected

What does not work as expected

Upvotes: 0

Views: 399

Answers (1)

RyanQuey
RyanQuey

Reputation: 725

It turns out I was adding a "where" clause to every query in a policy (eg, "where: {"status": "active"}}). Having a "where" in the query string automatically overrides the other params, and so nothing else was getting seen. (To be precise, if you have a where clause, other criteria never get seen)

For some reason, the "where" was also not working to set the search criteria for sails 0.12.13, so I ended up hacking the parseCriteria function actionUtils in sails and using the one they have for v.1 and that worked for me.

Hope that helps anyone in the future

Upvotes: 0

Related Questions