解析关系数据查询 [英] Parse relational data queries
问题描述
我是新来Parse.com和有麻烦我的设计数据库的结构,以及如何获取所需的数据。
I'm new to Parse.com and was having trouble designing the structure of my database, and how to retrieve the desired data.
在数据库中,每个用户
(主要标识符电子邮件)拥有的好友列表和状态
布尔。好友列表包含数据库中的其他用户的电子邮件。我需要获得状态
在一个单一的查询到服务器布尔为每个朋友在一个特定的用户列表,preferably。
In the database, each user
(primary identifier as email) has a list of friends and a status
boolean. The friend list contains the email of other users in the database. I need to get the status
boolean for each of the friends in a particular users list, and preferably in a single query to the server.
什么是设计我们的结构和检索这些数据的好办法。目前,我做了两个数据类(表),一个包含与布尔每个用户状态
,另一个包含每个用户和他们的朋友列表。首先,我不知道,如果这种结构去的正确方法。其次,我不知道该如何找回状态布尔在单个用户的好友列表每个用户。
What would be a good way to design our structure and retrieve this data. Currently, I made two data classes (tables), one containing each user with their boolean status
, and another containing each user and their list of friends. Firstly I was not sure if this structure is the correct way to go. Secondly, I don't know how to retrieve the status boolean for each user in a single users friend list.
修改我其实只是昨天发现的关系列的类型,但我无法弄清楚如何使用它。 1)如何人物角色链接至code用户?我明白我需要在这里,但使用对象ID怎么样?结果
2)我如何添加其他角色(在朋友)一个假面(用户)的关系。我无法填充这个关系列。我理解的查询可以在关系栏可以使用,但我不能达到那么远没有填充关系列。结果
3)我的查询到服务器,我会拉动整个表?比方说用户有2个朋友。有没有办法对我来说,只获取当前用户,和两个朋友,还是我拉着整个表,然后做我的过滤就可以了。我关心的是网络,如果我的用户表变得大而沉重。
Edit I actually discovered the relation column type just yesterday, but I was unable to figure out how to use it. 1) How do I link a Persona to a User in code? I understand I need to use ObjectID here, but how?
2) How do I add other Personae (friends) to a relation of a single Persona (the user). I was unable to populate this relation column. I understand query can be used on the relation column, but I couldn't reach that far ahead without populating the relation column.
3) In my query to the server, am I pulling the entire table? Lets say a user has 2 friends. Is there a way for me to fetch only the current user, and the two friends, or am I pulling the entire table, and then doing my filtering on it. I am concerned with the network being burdened if my table of users grows big.
修改嗯,我无法弄清楚关系查询完美,只是还没有,但是,我发现了一个很好的解决了我的问题。由于好友列表的变化很少,我会在这个列表脱机维护,导致单个查询到我的朋友的状态拉的服务器。伴随着这个名单,我可能会或可能不会决定也是我自己的数据来拉,并获得更新的好友列表。谢谢您的帮助虽然。
Edit Well I couldn't figure out relational queries perfectly just yet, however, I found a good solution to my problem. Since the list of friends changes very rarely, I'll be maintaining this list offline, resulting in a single query to the server of pulling in the status of my friends. Along with this list, I may or may not also decide to pull in my own data and get an updated friend list. Thank you for your help though.
推荐答案
在解析许多一对多的关系模型的方式与关系列类型。这是描述一个用户如何有很多朋友谁是用户的最佳选择。如果这是一个社会网络状的应用程序,建议的另一个好一点的是创建一个类 - 从分析用户不同的 - 这说明用户的公共人而言
The way to model many-to-many relations in parse is with the relation column type. This is the best choice to describe how a user has many friends who are users. If this is a social-network-like app, another good bit of advice is to create a class -- distinct from the parse User -- that describes users' public personae.
这是这样你就可以有分析用户类保留为您的应用程序和一个真实的人之间的私人客户关系(有建于安全性约束在这里)。这另一个表,说我们把它叫做假面,可以有一个指针类型的列到它的用户,保持这样的事情昵称,个人资料图片等,也让你的布尔状态。
This is so you can have the parse User class remain as the private, customer relationship between your app and a real person (there are built in security constraints here). This other table, say we call it Persona, can have a pointer-typed column to its user, keep such things as nickname, profile image, etc. and also keep your boolean status.
_user
类 - 默认的东西,标配解析,以及任何涉及您的应用客户关系
_User
class - default stuff that comes standard with parse, plus anything pertaining to the customer relationship with your app.
假面
- 指针_user表,布尔状态,其他公开信息,关系称为与这对其他假面朋友
Persona
- pointer to _User table, boolean status, other public info, relation called "friends" relating this to other Persona.
所以,对于一个已登录的用户和他/她当前选定角色(你的选择用户是否可以有一个以上的人而言),就可以得到朋友的人而言如下(以伪code):
So, given a logged in user and his/her currently selected persona (your choice whether users may have more than one personae), you can get friends' personae as follows (in pseudo code):
friendsRelation <- myPersona.friends
friendsQuery <- friendsRelation.query // query is a method on relation
run friendsQuery asynch, then the result will be allFriendsPersonae
for each persona in allFriendsPersonae
status <- persona.status
如果您选择不采取人物类意见,code上面是一样的,只是更换用户角色。
If you choose not to take the persona class advice, the "code" above is the same, just replace persona with user.
修改 - 在回答问题编辑:
1)由角色的用户列(指针类型)设置为用户对象链接人物角色的用户。要在以后获取的人物,当你只有一个用户,查询角色表,其中用户列等于用户。
Edit - in response to question edit: 1) Link a persona the user by setting the persona's user column (pointer type) to the user object. To get that persona later, when you only have a user, query the persona table where "user" column equals user.
2)的关系实现了一个add()方法。如果你有一个personaA,并希望personaB添加为好友,你 getRelation(朋友)
上personaA,并将其发送添加(personaB )
。
2) Relation implements an add() method. If you have a personaA, and want to add personaB as a friend, you getRelation("friends")
on personaA, and send it add(personaB)
.
3)你从关系中得到的查询只针对关系成员的查询。所以,如果personaA有两个朋友personaB和personaC,你会当您运行personaA的朋友查询,得到的只有B和C。
3) The query you get from a relation is a query only for members of that relation. So if personaA has two friends personaB and personaC, you'll get only B and C when you run personaA's friends query.
这篇关于解析关系数据查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!