Recupera todas las Parse.Relations que apuntan a un objeto determinado
-
12-12-2019 - |
Pregunta
estoy usando un Parse.Relation
para agrupar usuarios bajo un tema.¿Cómo recupero todos los temas que tienen un topic.relation
apuntando a un usuario determinado?
La pregunta es acerca de hacer esto en una sola llamada/devolución de llamada.
// 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.
Solución
Construya una consulta para la clase Tema y agregue una restricción igual a.
var query = new Parse.Query(Topic);
query.equalTo("friend", user);
query.find({success: function (returnedTopics) {
...
},
error: function (...) {
}
});
Esto devolverá todos los objetos de tema que contengan al usuario en su relación de amistad.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow