Получить все Parse.Relations, указывающие на данный объект.

StackOverflow https://stackoverflow.com//questions/11680540

Вопрос

я использую 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 и добавьте ограничение равенства.

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

Это вернет все объекты Topic, которые содержат пользователя в его дружеских отношениях.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top