모든 분석을 가져옵니다. 주어진 객체를 가리키는 관련성을 설명합니다
-
12-12-2019 - |
문제
Topic의 사용자를 그룹화하기 위해 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.
. 해결책
주제 클래스에 대한 쿼리를 구성하고 equalTo 제약 조건을 추가합니다.
var query = new Parse.Query(Topic);
query.equalTo("friend", user);
query.find({success: function (returnedTopics) {
...
},
error: function (...) {
}
});
.
이렇게하면 사용자가 사용자가 포함 된 모든 주제 객체를 반환합니다.
제휴하지 않습니다 StackOverflow