Reputation: 725
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
req.query
is getting set and read by policies (eg, ?userId=3
is found by req.param("userId")
)/api/posts?userId=3&populate=userId
populates the userId
field, (but still returns all posts for all users)?id=5
) filters and returns only one record as expectedPosts.find({userId: 3})
) works What does not work as expected
?userId=6
)?name=test
)where
(eg &where={"userId":1}
)Upvotes: 0
Views: 399
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