0

There are many ways to model a db for a simple task, but you will find at least one way that is the most efficient and the fastest.

For example: I have the following tables. User, Post and UserPost.

User
===========================
userId  |  userName
---------------------------
1          john
===========================

Post
===========================
postId  |  postContent
---------------------------
1          bla bla bla
===========================

UserPost
===========================
postId  |  userId
---------------------------
1          1
===========================

I think this is efficient in sql databases.

But what about Parse databases? Could you tell me what is the best option and how to get data using Java Android?

Option 1:

User
===========================
userId  |  userName
---------------------------
1          john
===========================

Post
===========================
postId  |  postContent
---------------------------
1          bla bla bla 
===========================

UserPost
===========================
post          |   user 
---------------------------
Post(pointer)     User(pointer)
===========================

Option 2:

User
===========================
userId  |  userName  |  post
---------------------------
1          john      |  relation(Post)
===========================

Post
===========================
postId  |  postContent  |  user
---------------------------
1          bla bla bla  |  pointer(User)
===========================

Option 3:

User
===========================
userId  |  userName
---------------------------
1          john
===========================

Post
===========================
postId  |  postContent
---------------------------
1          bla bla bla 
===========================

UserPost
===========================
postId  |  userId 
---------------------------
1          1       
===========================

So, the questions are: 1- What is the best way to model a Parse Classes for this simple task. If you have better solution, please let me know. 2- How to get specific user's posts in Android and Java (assume the user has 5k posts).

thanks

Hatim
  • 1,516
  • 1
  • 18
  • 30
  • You should probably benchmark 1 and 2 with a considerable sample. – nathan Aug 17 '17 at 02:51
  • Thanks Nathan, should I make pointer or relation in both classes or only in one of them? – Hatim Aug 17 '17 at 15:02
  • Your relation is 1-1 so maybe solution 3 is better than having to deal with relationships. Have a look at https://stackoverflow.com/questions/23459111/parse-using-relations-versus-pointers, https://stackoverflow.com/questions/26502749/relation-or-pointer and https://stackoverflow.com/questions/22157109/deciding-whether-to-use-a-one-to-many-many-to-many-or-one-to-one-relationship – nathan Aug 17 '17 at 15:56
  • I think the relation I should implement is 1 to many, as every user could have many posts. – Hatim Aug 17 '17 at 16:23
  • Yeah sorry, not sure why I thought 1-1. 1-n with a large number of posts, maybe relationships are the way to go instead of arrays. You should benchmark your solutions to be certain. – nathan Aug 17 '17 at 16:50
  • Thanks, so, to sum up, and according to the link you posted, (1) 1:n relationship, we should use Relation or Array if the size is predictable. (2) n:n relationship, we should create a new class that has two pointers. So, Option 2 wins. – Hatim Aug 17 '17 at 17:06

0 Answers0