解析:查询包含的指针
问题描述:
我有一个“产品”集合,它具有指向我在产品查询中包含的“类别”集合的指针引用。如何查询此类别值,而无需单独查询类别本身?解析:查询包含的指针
var productQuery = new Parse.Query("Product");
productQuery.include("category");
if(params.category) {
productQuery.equalTo("category", params.category);
}
...
productQuery.find({
success: function(products) {...},
error: function(err) {...}
});
什么不想:
var productQuery = new Parse.Query("Product");
productQuery.include("category");
if(params.category) {
var categoryQuery = new Parse.Query("Category");
categoryQuery.equalTo("name", params.category);
categoryQuery.first({
success: function(foundCategory) {
productQuery.equalTo("category", foundCategory);
}
});
// Yes, I am aware that in this example the product query below would likely be executed before the category query above finishes.
}
...
productQuery.find({
success: function(products) {...},
error: function(err) {...}
});
答
什么你要找的是一个Parse.Query的matchesQuery或matchesKeyInQuery方法:http://parseplatform.org/Parse-SDK-JS/api/classes/Parse.Query.html#methods_matchesQuery
它会基本上尽你所能做的事情,除非更有效率,并且在您编写的高级代码上更干净。
https://stackoverflow.com/questions/26923172/query-on-pointer-in-parse-com-objects-in-javascript相当相关 –