将查询条件添加到相关对象'的属性

Add Query conditionals to related object's properties in parse.com with JS SDK

本文关键字:属性 对象 条件 查询 添加      更新时间:2023-09-26

是否可以对parse.com中的相关对象排序并使用条件语句?

我有一些用户,他们有一个指向profilePictures的指针。我想要一个查询,例如:

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");

不幸的是,这从parse.com返回了一个105错误,因为它找不到属性。。。

{"code":105,"error":"profilePicture.updatedAt is not a valid order key"}

我发现的所有帖子都很旧(2012年),最近可能有什么变化。你知道如何做到这一点吗?

对于排序,我真的不在乎。我已经实现了一个比较器,但我需要按日期进行筛选,因为我不能免费查询1000个配置文件。

使用include和点表示法无法实现这一点。您最好使用内部查询:

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
  }
});