Deciding whether to use a one-to-many, many-to-many, or one-to-one relationship with Parse.com for iOS photo sharing app

StackOverflow https://stackoverflow.com/questions/22157109

Question

I am creating a photo sharing app for the iPhone using Parse.com and so far everything has been pretty easy and I just finished writing the code for uploading photos to the Parse server.

So far, I have been using the default "_User" class. Here are some of the key types of data that are being stored for each user: objectId, username, email, and an array object called "friends" that contains the usernames of other users in the database that the user has added to their friends list.

Now, I need to setup the actual sharing functionality between users. I have been going through the Parse documentation and I need to decide whether to use a one-to-many, many-to-many, or one-to-one relationship. Depending on which one I end up choosing, I then will need to decide between using pointers, arrays, parse relations, or join tables.

I am going to quickly explain the "sharing" functionality that I am trying to achieve:

  1. For my photo app, user1 starts the "relationship" by taking a photo and choosing to send it to a friend on their friends list named user2 .

  2. The photo is then uploaded to Parse and sent to user2.

  3. user2 receives the photo from user1.

  4. user2 opens the photo and it is their job to "finish" the "relationship" by using the app's editing tools and drawing something random on the original photo. Example: user2 draws a heart next to user1's face in the photo.

  5. When user2 is finished, the final photo is saved to their profile and also sent back to the original sender, user1, and the "relationship" is now finished and completed/closed.

After reading through the docs and doing my own research, I have come to the conclusion that I need to use a Many-To-Many relationship using Join Tables so that I can include metadata.

However, I am new to objective-c and programming in general and it would be lazy of me if I did not ask for input and advice before getting started when it is possible that I have chosen the wrong solution or an unnecessary solution.

Was it helpful?

Solution

Your question is more about your DB management than anything to do with Obj-C.

Think about using a new class in your DB called SharedImage which hosts the image(s), a link to the originator and the recipient (1 to 1, so could us a pointer or a relationship) and any other data you need.

Now you can create these objects are you require and you can fetch them based on queries using the current user.

Also, for your existing friends array which you said holds the usernames of the friends - it would probably be better to store the objectIds of the friends instead of the usernames (because the username can usually be changed, but the objectId is static).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top