Parse platform 仅具有对象ID的查询解析关系

Parse platform 仅具有对象ID的查询解析关系,parse-platform,Parse Platform,我想对具有关系列的类执行解析查询。据我所知,我不能用云函数传递整个关系对象,我只能将objectId作为字符串传递 因此,在我的iOS应用程序中,我通过如下方式传递objectId: PFCloud.callFunctionInBackground("customReport", withParameters: ["thing":thing.objectId]){ (response, error) -> Void in println(response) } //In my Clo

我想对具有关系列的类执行解析查询。据我所知,我不能用云函数传递整个关系对象,我只能将
objectId
作为字符串传递

因此,在我的iOS应用程序中,我通过如下方式传递
objectId

PFCloud.callFunctionInBackground("customReport", withParameters: ["thing":thing.objectId]){ (response, error) -> Void in
  println(response)
}
//In my Cloud Code function...    
var ThingObject = Parse.Object.extend("Thing")
var temporaryThing = new ThingObject()

temporaryThing.id = request.params.thing
query.equalTo('thing',temporaryThing)
然后在我的云代码函数中:

Parse.Cloud.define("customReport", function(request, response) {
  var promises = []

  var query = new Parse.Query("MyClass")

  //Search for thing
  if(request.params.thing != ""){
    query.equalTo('thing',request.params.thing)

    var promise1 = query.find()

    promises.push(promise1) 
  }

  //...

})
但是这不起作用,因为
equalTo
语句需要一个
对象,而不是
objectId


是否有一种方法可以只查询与
对象ID
的关系?
或者我必须使用
对象ID
查询
对象,然后执行
等价检查?

如果正确,您不能直接传递关系对象。您可以做的是在关系列中传递正在搜索的对象的objectId,然后查询关系列与objectId相等的类

下面是一个示例,如果您在_User类上有一个名为“friends”的关系列,并且您在iOS应用程序中传递了_User对象的objectId:

Parse.Cloud.define("getFriends", function(request, response) {
    var userId = request.params.userId;

    var query = new Parse.Query(Parse.User);
    query.equalTo("friends", userId);
    query.find({
        success: function(friends) {
            response.success(friends);
        },
        error: function(error) {
            response.error(error);
        }
    });
});
看起来您毕竟可以通过
objectId
进行查询。您只需先创建一个ID为的空对象,如下所示:

PFCloud.callFunctionInBackground("customReport", withParameters: ["thing":thing.objectId]){ (response, error) -> Void in
  println(response)
}
//In my Cloud Code function...    
var ThingObject = Parse.Object.extend("Thing")
var temporaryThing = new ThingObject()

temporaryThing.id = request.params.thing
query.equalTo('thing',temporaryThing)

你绝对可以使用includeKey

基本上,当myQuery.includeKey(“collumnName”)获取指向该键的指针的对象时,它将获取该键的整个对象。二比一

更多:


您必须将id更改为指针,然后才能将其传递到query.whereEqualTo


隐马尔可夫模型。。。有趣。不过,这并不是我想要做的。在您的示例中,我尝试这样做:让所有用户都使用好友“Sam”。我没有用户ID,无法将其缩小到特定用户。但您可以通过在iOS应用程序中传递用户“Sam”的objectId,对吗?是的,我可以使用Sam的
objectId
。请参阅我的更新答案。您只需要查询关系列与objectId相等的位置。