Reputation: 3000
It is possible to sort and use conditionals to a related object in parse.com?
I have Users which have a pointer to profilePictures. I would like a query such as:
var query = new Parse.Query(Parse.User);
// include images
query.include("profilePicture");
// get only regular users
query.notEqualTo("isAdmin", true);
// who has uploaded an image
query.exists("profilePicture");
// and such image was updated in the last month
query.lessThanOrEqualTo("profilePicture.updatedAt", today);
query.greaterThanOrEqualTo("profilePicture.updatedAt", lastMonth);
// and order the resultset by profilePicture.updatedAt
query.ascending("profilePicture.updatedAt");
Unfortunatelly this returns a 105 error from parse.com as it can't find the property...
{"code":105,"error":"profilePicture.updatedAt is not a valid order key"}
All the posts I find are quite old (~2012) and maybe something changed lately. Any idea on how to achieve this?
For sorting I don't really care. I've alrady implemented a comparator, but I need to filter by date as I can't query for 1000's of profiles for nothing
Upvotes: 3
Views: 190
Reputation: 2717
You cannot achieve that with include
and dot-notation. You better use inner queries for this:
var innerQuery = new Parse.Query("PICTURES"); // query on your profile picture class
innerQuery.lessThanOrEqualTo("updatedAt", today);
innerQuery.greaterThanOrEqualTo("updatedAt", lastMonth);
var query = new Parse.Query(Parse.User);
query.matchesQuery("profilePicture", innerQuery); // users that match the picture criteria
query.find({
success: function(users) {
// You get selected users with the profilePicture criteria
}
});
Upvotes: 4