0

所以我在我的 Parse DB 中有一个这样的对象Follow......

Follow
---------------
PFUser follower
PFUser followee

即这是一个多对多“跟随”结构的连接表。一个用户可以关注很多用户,一个用户可以被很多用户关注。

无论如何,我正在尝试创建一个查询,它只返回一个对象数组,PFUser这些对象是以下用户currentUser

我是这样开始的...

PFQuery *followQuery = [Follow query];
[followQuery whereKey:@"follower" equalTo:[PFUser currentUser]];

这将返回一个跟随对象的数组,但我不想要这些。我想要 PFUser 对象的数组,但我不知道如何从这里到达那里。

我觉得这应该比我做的容易得多。哈哈!

4

2 回答 2

1

这要容易得多。更难,取决于你的心态。你明显的心态:SQL :-)

在使用 Parse(或其他 NoSQL 数据存储)时,尤其是在移动设备上,首先关注您的查询,并创建一个模型,使常用查询保持简单和尽可能少,并且在设备上进行计算最低限度。

对于您的用例,创建一个类来保存数组中每个用户的所有关注者和所有关注者。

我在较早的答案中对此进行了解释: https ://stackoverflow.com/a/22449103/1485715

此外,正如该答案中所链接的,Java 的 Twissandra 项目是关于如何为 NoSQL 建模的一个很好的入门(适用于所有程序员;不仅仅是 Java 程序员): https ://github.com/twissandra/twissandra

于 2014-05-08T16:48:54.857 回答
0

You existing structure works, the issue is that you have a return result that is an array of Follow objects, and you want an array of followee.

First off you probably want to tell the query to includeKey for followee so that you have the full user instead of just a pointer with an ID.

Secondly you want to map the results, which you can do just like you would any other array of objects you want to read a property out of. Just use a loop.

于 2014-05-08T19:43:14.220 回答