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

6
  • You should probably benchmark 1 and 2 with a considerable sample. Commented Aug 17, 2017 at 2:51
  • Thanks Nathan, should I make pointer or relation in both classes or only in one of them? Commented Aug 17, 2017 at 15:02
  • Your relation is 1-1 so maybe solution 3 is better than having to deal with relationships. Have a look at stackoverflow.com/questions/23459111/…, stackoverflow.com/questions/26502749/relation-or-pointer and stackoverflow.com/questions/22157109/… Commented Aug 17, 2017 at 15:56
  • I think the relation I should implement is 1 to many, as every user could have many posts. Commented Aug 17, 2017 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. Commented Aug 17, 2017 at 16:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.