I'm current working on a SQLite-database in a android project which will store 3 types of objects; feed, users and posts.
There will be several feeds containing several varying users(a user can be part of serveral feeds) and of my understanding i should implement this by having a Many-to-Many relationship: feedTable - bridge_feeduserTable - userTable
But there will also be posts made by users and a post should be linked to a the user which created the post. How should i link this up?
Should i have a feedTable - bridge_feeduserTable - userTable - bridge_userpostTable - postTable?
or should the posts be stored in a separate database with all the posts? What is the best practice regarding this issue?
Some basic questions that will asked to the database is:
What users are part of feed x?
What posts have been made by the users in feed x?
-
Is every post made by one user and for one feed? Or are there posts that do not belong to a feed?ypercubeᵀᴹ– ypercubeᵀᴹ2012年10月07日 09:12:43 +00:00Commented Oct 7, 2012 at 9:12
1 Answer 1
If I get you right then one post is linked to one user but one user can have many posts. I think this is a one to many relationship. So, put a field user_id in your table post then you know which post is linked to which user.
It's a german page but the first image would help you.
-
Sorry, i was not clear enough. The bridge_userpostTable will have a user_id and a post_id which ofcourse will enable a query for a user_id (giving ID to all posts). Do you think the bridge_userpostTable is unnecessary and a postTable with user_id column is enough?Rawa– Rawa2012年10月05日 21:49:55 +00:00Commented Oct 5, 2012 at 21:49
-
Do you think the bridge_userpostTable is unnecessary and a postTable with user_id column is enough? <- If one post is linked to one user then yes. If one post is linked to many users then you need three tables. I UPDATET THE ANSWERJackTools.Net– JackTools.Net2012年10月05日 22:01:44 +00:00Commented Oct 5, 2012 at 22:01
-
Thanks for the answer, the picture added resolved my question. (:Rawa– Rawa2012年10月05日 22:29:32 +00:00Commented Oct 5, 2012 at 22:29