简体   繁体   中英

How to use Parse.com ParseRelation

I have an app that has a Parse "User". The user is an Admin of sorts. Underneath the admin we have a "regular user". These regular users do not sign up through Parse, but are just ParseObjects that are tied to other data via "parenting".

They are connected to the Admin user via regularUser.put("user",ParseUser.getCurrentUser());

An admin can click a "Share" button to share this regularUser and all their accompanying data with another Admin user.

My problem is I don't know the best way to do this. How can I make a regular user belong to one or more Users?

I'm not sure when its best to tie data to a user vs. adding an object to a "Parent" vs a ParseRelation (which i still don't quite understand).

I come from an SQL background with primary/foreign keys and I don't see a direct comparison between SQL and Parse relationships. Help me figure this out please.

在此处输入图片说明

You might find it less confusing if you thing of your "Regular User" objects as something else, maybe colors. Lets call "User 1" Red, "User 2" Green, "User 3" Blue.

OK so now we want to let Parse User 1 say they like Red and Green. Parse User 2 likes Green and Blue.

In parse.com you can store references, so where you would have a many-to-many join table in SQL you can create the same in Parse if you want, or you can just store reference links in one side and/or the other.

For example you could have an array (if you don't expect there will be too many) on the Parse User object. This property can be named whatever you like ("users" in your case, "colors" in my example).

Look at this documentation on how to use the array in Android code. There's another section on how to query using arrays .

I see many questions on relations/pointers/etc, you'll find more information if you look using the parse.com tag.

It would be nice if they could post some general information about relationships in their documentation I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM