ios - leancloud如何做复杂的复合查询?
怪我咯
怪我咯 2017-04-17 16:52:03
0
1
369

我有两个class,一个是user,一个是userInfo。
其中userInfo里面有一个字段叫userId,是一个pointer,就是user。还有一个字段是version,类型是string。

现在我要查询userInfo里面version是1.0的所有用户,按照时间排序。

目前我的方案是先获取userInfo里面符合条件的userId,然后再获取所有userId的数据。但是这样就做了两次网络请求。
能不能一次获取呢?

let infoQuery = UserInfo.query()
infoQuery.whereKey("version", equals: "1.0")
infoQuery.orderByDescending("updatedAt")

上面的代码获取的是userInfo的结果,我想要user的结果,如果用user进行query,那么就还要在userInfo里面去查询一次。
有没有只做一次查询的解决方案呢?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
Ty80

Already solved.
User should not be put into UserInfo as pointer. You should put UserInfo into User and that's it.
In other words, there is a userInfo field in the User table, and its type is Pointer. There is only the version field in UserInfo.
In this way, you can use the following code to make queries.

AVQuery *innerQuery = [AVQuery queryWithClassName:@"UserInfo"];
[innerQuery whereKeyExists:@"version"];
AVQuery *query = [AVQuery queryWithClassName:@"_User"];
[query whereKey:@"userInfo" matchesQuery:innerQuery];
[query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error) {
    // 
}];

If you have a better solution, please suggest it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!