【问题标题】:Parse cloud code not working as expected with pointers (query.include)使用指针解析云代码未按预期工作 (query.include)
【发布时间】:2017-05-11 22:42:10
【问题描述】:

数据库有一个“照片”类。这个类有一个指向“用户”类的指针。

我使用这个云代码:

Parse.Cloud.define("AllPhotos", function(request, response) {
var query = new Parse.Query("Photos");

var userPointer = {"__type":"Pointer","className":"User","objectId":request.params.userId}; 

query.equalTo("active", true);
query.equalTo("userId", userPointer); 
query.descending("createdAt");
query.include("_User");  
query.find({
success: function(results) {

    response.success(results);
},
error: function() {
    response.error("Error 000");
}
});
});

当我查询“AllPhotos”时,我希望在没有其他查询的情况下获得用户对象(带有用户名、名称等),但结果如下:

<Photos: 0x6080004a0240, objectId: k2SvMOVJ7s, localId: (null)> {
active = 1;
image = "<PFFile: 0x60800064cdb0>";
likes = 0;
userId = "<PFUser: 0x6080002e9300, objectId: gHfS6dzrag, localId: (null)>";
}

它只给了我 objectId,我需要再次查询用户类以获取用户名和名称。

如何在不进行其他查询的情况下进行检索?

【问题讨论】:

    标签: javascript parse-server parse-cloud-code


    【解决方案1】:

    userId 是什么类型?看起来您的 userId 实际上是指向用户的指针?如果是这样,您需要致电query.include("userId"),而不是query.include("_User")。 _User 是 Parse.user 的底层类。当您使用包含时,您需要包含 字段名称 一个指针存储在其下。

    【讨论】:

    • 我也尝试使用“userId”。我不知道发生了什么。我更新了解析服务器,现在它可以工作了!谢谢!
    • @Jake T. 你能帮我解决类似的问题吗?谢谢
    • 如果你把我链接到一个问题,我也许可以。
    猜你喜欢
    • 2020-12-26
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多