解析云代码新的SDK包含子类不起作用 [英] Parse cloud code new SDK include subclass not working
问题描述
我使用的是旧的解析SDK版本1.5.0,并且我的函数返回了所有包含项. 现在,我尝试使用最新的SDK,并且该功能仅返回主对象(在门和位置上,我仅获得指针".)
I was using an old parse SDK version 1.5.0 and my function was returning with all the includes. Now I tried to use the latest SDK and the function is returning the main object only (on the gate and location I get "pointers" only.).
这是代码:
Parse.Cloud.define("get_gates_for_user", function(request, response) {
var userId = request.params.userId;
var gateToUserQuery = new Parse.Query("GateUserJoinTable");
gateToUserQuery.equalTo("user", {
__type: "Pointer",
className: "_User",
objectId: userId
});
gateToUserQuery.include("gate");
gateToUserQuery.include("location");
gateToUserQuery.find({
success: function(results) {
response.success(results);
},
error: function(error) {
console.log(error.message);
response.error(ERROR_CODE_GENERAL_ERROR);
}
});
});
推荐答案
我最近开始使用Parse,所以我对旧版SDK的行为不太熟悉.
I started working with Parse recently so I'm not very familiar with the behavioiur of old SDK versions.
但是,由于您使用的是Cloud Code,因此.include()
不能保证与.fetch()
相比,性能不会显着提高,因为该代码在其基础架构上运行(这是访问相关的Parse.Object
的有据可查的方式,因此他们仍然应该为此进行优化),因此以下应该可行:
Since you're in Cloud Code, however, .include()
doesn't warrant a significant performance gain over .fetch()
, since the code runs on their infrastructure (it's the documented way of accessing related Parse.Object
s, so they should be optimizing for that anyway), so the following should work:
var _ = require('underscore');
var results;
gateToUserQuery.find().then(function (joins) {
// add results to bigger-scoped variable
// for access in the other function
results = joins;
// Promises are beautiful
var fetchPromises = _.map(results, function (join) {
return Parse.Promise.when([
join.get('gate').fetch(),
join.get('location').fetch()
]));
});
return Parse.Promise.when(fetchPromises);
}).then(function () {
// related Pointers should be filled with data
response.success(results);
});
我认为至少在SDK的当前版本中,
I think at least in the current iteration of the SDK, include
only works with Arrays instead of Pointers.
这篇关于解析云代码新的SDK包含子类不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!