首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取指向给定对象的所有Parse.Relations

获取指向给定对象的所有Parse.Relations
EN

Stack Overflow用户
提问于 2012-07-27 10:08:02
回答 1查看 4K关注 0票数 2

我正在使用Parse.Relation将用户分组到一个主题下。如何检索具有指向给定用户的topic.relation的所有主题?

问题是如何在单个调用/回调中做到这一点。

代码语言:javascript
复制
// first add() a User object to the Topic's Parse.Relation
this.friendRelation = this.topic.relation("friend");
this.friendRelation.add(user);
// save the Topic to save its newly added .relation to Parse/Mongo
this.topic.save();

// iterate by adding the same User to several Topics

// (...)

// then you want to retrieve all Parse.Relations of all Topics where that 
// specific user is pointed to

// the non-optimized way is to traverse every row in the Topics index 
// and query each topic for its relations to find matching pointers to our user, 
// which means that the number of calls is bound to the number of rows – fine for
// 10 topics in Mongo but passed 100 it won't be tolerable.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-28 02:17:53

为Topic类构造一个查询,并添加一个equalTo约束。

代码语言:javascript
复制
var query = new Parse.Query(Topic);
query.equalTo("friend", user);
query.find({success: function (returnedTopics) {
    ...
    },
    error: function (...) {
    }
});

这将返回所有在其好友关系中包含user的Topic对象。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11680540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档