带有子查询的Parse.com iOS查询有时不起作用

时间:2015-09-14 14:35:58

标签: ios parse-platform

        let subQuery = PFUser.query()!
        let lang = NSBundle.mainBundle().preferredLocalizations[0] as! String
        subQuery.whereKey("lang", equalTo: lang)
        let user = PFUser.currentUser()!
        let query = PFQuery(className: "Enquiry")
        query.whereKey("owner", notEqualTo: user)
        query.whereKeyDoesNotExist("answer")
        query.orderByDescending("createdAt")
        query.whereKey("skipped", notEqualTo: PFUser.currentUser()!)
        query.whereKey("owner", matchesQuery: subQuery)
        query.getFirstObjectInBackgroundWithBlock { (object: PFObject?, error: NSError?) -> Void in

上面的代码在开发过程中完美无缺,数据库中有大约1000条记录。但不超过3000.有许多记录与查询匹配,但大多数会返回No results matched the query. (Code: 101, Version: 1.8.1)的错误。 删除子查询可以解决问题。但我需要检查正确的语言。我想,一个用户记录缺少一个lang条目,但它们都已设置好。 为什么子查询不能正常工作?我可以使用云代码以某种方式更新应用程序吗?这是一个解析sdk错误吗?

1 个答案:

答案 0 :(得分:0)

(values correct at the time of writing)

Any query is limited to 100 return items by default, and you can optionally change that limit up to 1000.

So, your subquery is getting the first 100 users with the specified language and the default sort ordering. If those users don't have any non-skipped enquiries for the current user without an answer then the result set will be empty.

To verify this is the issue you can set the limit on the subquery to 1000. Note that it's still possible you won't get any results, but it forms a good base test.

It isn't a bug, though it isn't useful. It also isn't possible to fix without some code change.

In general you'll probably need to switch to cloud code so you can iterate through the users until you get to the end or find the requisite number of results to return. Cloud code will allow you to do this faster than the app could do and to change the logic in future without having to make another app release.

相关问题