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

Javascript 获取指向给定对象的所有Parse.Relations,javascript,backbone.js,parse-platform,Javascript,Backbone.js,Parse Platform,我正在使用Parse.Relation将用户分组到一个主题下。如何检索具有指向给定用户的topic.relation的所有主题 问题是如何在单个调用/回调中执行此操作 // 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 sa

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

问题是如何在单个调用/回调中执行此操作

// 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.

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

var query = new Parse.Query(Topic);
query.equalTo("friend", user);
query.find({success: function (returnedTopics) {
    ...
    },
    error: function (...) {
    }
});

这将返回所有包含用户好友关系的主题对象。

请发布一些代码,帮助我们更清楚地理解您的问题。嗨,Sheikh,这里是一些设置多对多关系的初始代码。现在制作迭代器给你一个想法,这是低效的。是的,太棒了,谢谢你!基本上,如果我做对了,一旦使用
主题
上的
.relation()
建立了关系索引,我就可以以正常方式查询它,其中键是关系的名称。我个人发现“父级”和“包含”功能的概念也很有用:这仍然受支持吗?我在使用SDK 1.2.17时遇到问题。