Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何查询";或;在解析中使用includeKey?_Ios_Swift_Parse Platform_Fetch - Fatal编程技术网

Ios 如何查询";或;在解析中使用includeKey?

Ios 如何查询";或;在解析中使用includeKey?,ios,swift,parse-platform,fetch,Ios,Swift,Parse Platform,Fetch,所以,我在Parse和Place模型中使用了事件模型。每个模特都有自己的位置。我还有用户,每个事件都有所有者。 所以,我需要获取我的活动,或者在我所在位置周围10英里范围内的活动 获取我使用的事件 let query = Event.query() query.whereKey("author", containedIn: [PFUser.currentUser()!]) query.includeKey("place") 它可以工作,但现在我需要添加或操作,并

所以,我在Parse和Place模型中使用了事件模型。每个模特都有自己的位置。我还有用户,每个事件都有所有者。 所以,我需要获取我的活动,或者在我所在位置周围10英里范围内的活动 获取我使用的事件

let query = Event.query()
        query.whereKey("author", containedIn: [PFUser.currentUser()!])
        query.includeKey("place")
它可以工作,但现在我需要添加或操作,并在10英里内查找事件 我用

我需要如何进行主查询才能使用其中的两个? 我试过了

 var resultQuery:PFQuery = PFQuery.orQueryWithSubqueries([query, placeQuery])

但它给了我一个错误,即orQueryWithSubqueries需要使用相同的类,此时您有一个返回事件列表的查询,然后是一个返回位置列表的查询

这就是为什么会出现错误

它们都需要返回相同的类型。然后你可以把它们“或”放在一起

像这样

let authorQuery = Event.query()
authorQuery.whereKey("author", containedIn: [PFUser.currentUser()!])

// note I'm using the "place.location" path to refer to the location key of the place key. 
let placeQuery = Event.query()
placeQuery.whereKey("place.location", nearGeoPoint: geoPoint, withinMiles: 20.0)
只有这样,才能在复合查询中包含键。在子查询上使用Include键时不起作用

let resultQuery:PFQuery = PFQuery.orQueryWithSubqueries([authorQuery, placeQuery])
resultQuery.includeKey("place")
现在,这将返回一个事件列表,每个对象中都填充了Place键

编辑

进一步阅读说明,复合查询不支持多种内容

但是,请注意,在复合查询的子查询中,我们不支持地理点或非过滤约束(例如,nearGeoPoint、WithingGeobox…:、limit、skip、orderBy…、includeKey:)

看起来您必须为此创建一个云函数

使用云函数,您可以传入位置并运行两个单独的查询,然后在返回它之前将它们组合到now数组中

您必须使用Javascript编写此代码,尽管使用的是云代码

编辑2

事实上,你可以试试这个

let authorQuery = Event.query()
authorQuery.whereKey("author", containedIn: [PFUser.currentUser()!])

// note I'm using the "place.location" path to refer to the location key of the place key. 
let placeQuery = Place.query()
placeQuery.whereKey("location", nearGeoPoint: geoPoint, withinMiles: 20.0)

let eventPlaceQuery = Event.query()
eventPlaceQuery.whereKey("place", matchesQuery: placeQuery)

let resultQuery:PFQuery = PFQuery.orQueryWithSubqueries([authorQuery, eventPlaceQuery])
resultQuery.includeKey("place")

这可能有同样的限制,不允许您创建它,但值得一试D

你想退回什么?事件列表或地点列表?列表事件(我是作者或在我的位置附近)添加了一个答案OK。它给了我一个错误:捕获的“NSInvalidArgumentException”带有“原因”或查询不支持包含“@nabiullinas”的子查询,因为我刚看了一眼,or查询也不支持地质点查询。
let authorQuery = Event.query()
authorQuery.whereKey("author", containedIn: [PFUser.currentUser()!])

// note I'm using the "place.location" path to refer to the location key of the place key. 
let placeQuery = Place.query()
placeQuery.whereKey("location", nearGeoPoint: geoPoint, withinMiles: 20.0)

let eventPlaceQuery = Event.query()
eventPlaceQuery.whereKey("place", matchesQuery: placeQuery)

let resultQuery:PFQuery = PFQuery.orQueryWithSubqueries([authorQuery, eventPlaceQuery])
resultQuery.includeKey("place")