我在 Parse 中有两个表:Product
和 Introduction
。
Introduction 有一个指针列 product
和一个字符串列 status
。
我可以使用 GET 介绍请求 (Parse documentation) 中的以下参数轻松检索所有状态为“实时、已验证”的介绍:
{
where = {
status = {
"$in" = (
live,
validated
);
};
};
}
现在,我想检索所有介绍,例如,所有产品 ID 等于“Jpun01VJ3c,AkxTvIdZTQ”。
我尝试了以下参数(我也尝试在 $in
中只使用一个 ObjectId 数组:“$in” = (Jpun01VJ3c, AkxTvIdZTQ);)。
{
where = {
product = {
"$in" = (
{
"__type" = Pointer;
className = Product;
objectId = Jpun01VJ3c;
},
{
"__type" = Pointer;
className = Product;
objectId = AkxTvIdZTQ;
}
);
};
};
}
所以,问题是: 我们如何才能检索带有产品列表的介绍?
你有什么建议吗?
ps:像这样只检索特定产品的一个介绍是没有问题的:
{
where = {
product = {
"__type" = Pointer;
className = Product;
objectId = Jpun01VJ3c;
};
};
}
谢谢
最佳答案
在这种情况下,您可能希望使用 matchesQuery
而不是 containedIn
。
以下代码是 JS 但易于翻译:
var productQuery = new Parse.Query("Product");
productQuery.containedIn("objectId", [ YOUR LIST OF IDs ]);
var introductionQuery = new ParseQuery("Introduction");
introductionQuery.matchesQuery("product", productQuery);
introductionQuery
.find()
.then(function(introductions) {
[...]
});
有关 iOS 的更多信息:https://parseplatform.github.io/Parse-SDK-iOS-OSX/api/Classes/PFQuery.html#/c:objc(cs)PFQuery(im)whereKey:matchesQuery :
关于ios - 使用指针列表 (where, $in) 解析包含在中的查询约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42000698/