【发布时间】:2018-07-07 06:57:21
【问题描述】:
这是我的担忧:
我有一个表 A,其中包含一组属性,包括位置属性(仅供参考,表中没有指针) 我有一个表 B,其中包含一组属性和一个指向表 A 中唯一对象的指针(使用表 A 的 objectId 属性)。表 B 中的多个对象可能有相同的指针。 所以基本上,表 A 中的每个对象都有几个从表 B 指向它的对象。
我想要实现的是使用以下方法过滤特定位置内表 A 中的所有元素:(请注意代码示例中的通用名称)
let queryA = PFQuery(className: "tableA")
queryA.whereKey("location", nearGeoPoint: location, withinMiles: 5)
工作正常,然后从表 B 中获取所有元素指向过滤后的元素.. 这是第一个问题,因为表 A 没有指针,似乎没有办法直接从表 A 中实现这一点,有吗?
所以我尝试的是根据表 A 中过滤的对象开始过滤表 B 中的所有对象,这导致我:
// Filtering all objects in table A according to a specific PFGeoPoint.
let queryA = PFQuery(className: "tableA")
queryA.whereKey("location", nearGeoPoint: location, withinMiles: 5)
// Filtering all elements in table B according to filtered elements from table A
let queryB = PFQuery(className: "tableB")
queryB.includeKey("pointer")
queryB.whereKey("pointer", matchesKey: "objectId", in: queryA)
// and then fetch the objects
queryB.findObjectsInBackground() { objects, error in
print(objects)
}
这不起作用,因为matchesKey似乎必须在同一个类下运行。
然后,我尝试使用 queryA 在某个位置从表 A 中查找所有对象,并使用 for 循环遍历方法 findObjectsInBackground 和 Block — [PFObject] — 的结果,并在每次迭代时运行另一个 findObjectsInBackground使用每个 PFObject 元素中的 objectId 并使用 whereKey 和 a 将其传递给 queryB
PFObject(withoutDataWithClassName: <>, objectId: <>)
这可行,但会导致异步问题,对我来说似乎不太合适。
有什么想法吗?
谢谢。
【问题讨论】:
标签: swift pointers parse-platform pfquery