我的_User表中有两个数组:hasCreated和isMemberOf,它们包含属于Group表的组对象,我有以下Cloud Code:
Parse.Cloud.beforeSave('Group', function(request, response) {
var creator = request.user;
if (!_.isObject(creator)) {
response.error('creator is not specified');
}
else {
var group = request.object;
var isCreate = group.isNew();
// Group is being created
if (isCreate) {
if (!_.isString(group.get('title'))) {
response.error('group title is required');
}
else {
group.set('createdById', creator.id);
response.success();
}
}
// Group is being updated
else {
response.success();
}
}
});
Parse.Cloud.afterSave('Group', function(request) {
var creator = request.user;
var group = request.object;
var wasGroupCreated = !group.existed();
if (wasGroupCreated) {
creator.addUnique('hasCreated', group);
creator.addUnique('isMemberOf', group);
creator.save();
}
});
Parse.Cloud.afterDelete('Group', function(request) {
var creator = request.user;
var group = request.object;
creator.remove('hasCreated', group);
creator.remove('isMemberOf', group);
creator.save();
});
当我发布到组时,它会按预期发生,但是当我用
获取用户时includeKey=isMemberOf&hasCreated
我得到以下内容:
hasCreated: [
{
__type: Object,
className: Group,
createdAt: 2014 - 06 - 04T18: 59: 02.325Z,
createdById: abc,
…
}
{
__type: Pointer,
className: Group,
objectId: def
}
{
__type: Pointer,
className: Group,
objectId: ghi
}]
isMemberOf: [
{
__type: Object,
className: Group,
createdAt: 2014 - 06 - 04T18: 59: 02.325Z,
createdById: abc,
…
}
{
__type: Pointer,
className: Group,
objectId: def
}
{
__type: Pointer,
className: Group,
objectId: ghi
}]
所以基本上,我只是完全取回了三个组中的一个,而且_type字段也是不同的。以下是我在User表中hasCreated和isMemberOf数组字段中的内容:
[{
"__type": "Pointer",
"className": "Group",
"objectId": "abc"
}, {
"__type": "Pointer",
"className": "Group",
"objectId": "def"
}, {
"__type": "Pointer",
"className": "Group",
"objectId": "ghi"
}]
我做错了什么?我需要为每个组获取完整的对象。请指教!谢谢!
答案 0 :(得分:0)
对于Parse来说,这个看起来像是一个暂时的问题(对我来说只持续了几天)。 include(not includeKey)已经可靠地给了我很长时间的完整对象了。