Spentak
Spentak

Reputation: 3359

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.

enter image description here

Upvotes: 1

Views: 1973

Answers (1)

Timothy Walters
Timothy Walters

Reputation: 16874

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.

Upvotes: 1

Related Questions