Frage

Ich verwende ein Parse.Relation um Benutzer unter einem Thema zu gruppieren.Wie rufe ich alle Themen ab, die eine haben topic.relation auf einen bestimmten Benutzer verweisen?

Die Frage besteht darin, dies in einem einzigen Anruf/Rückruf zu tun.

// 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.
War es hilfreich?

Lösung

Erstellen Sie eine Abfrage für die Topic-Klasse und fügen Sie eine equalTo-Einschränkung hinzu.

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

Dadurch werden alle Topic-Objekte zurückgegeben, die user in ihrer Freundesbeziehung enthalten.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top