chris
chris

Reputation: 36957

mySQL one-to-many data storage

I've only recently learned of the concept of one-to-many so excuse me if this is a bit vague or out of context per se.

Currently I am trying to figure out what is the best way to build up my tables in a social-esque manner. What I am trying to ultimately achieve is the Google+ wall. Where, say, people who are following me, or people I choose to see a post can see what I post. I know I am going to want two or three tables to sort this mess. It's just how to store it so I can then query against it is where I am having trouble wrapping my head around the logic.

Currently I am envisioning one table where I store a member id, and post (with any other associated data like timestamps etc.). Another table where I have the friend associations between two friends, and a third table that stores something else so I can use it as a cross-reference of sorts. But I don't know if I am thinking this through the right way. As I said I'm new to the idea; I can't picture it fully. So does anyone have any suggestions how to build these tables out? Not really looking to figure out how to query them currently. Just trying to figure out how to use the one-to-many concept properly, and all the reading I have done on the subject really hasn't given me much to work with in the form of examples even relatively close to what I want to do.

Upvotes: 0

Views: 308

Answers (1)

ChrisPadgham
ChrisPadgham

Reputation: 870

You will need one table for members

Members (memberId, MemberName, DateJoined etc)

One for posts with a foreign key to members

Post (PostId, MemberId, PostDate, etc)

One for whose following who

Following (FollowerId, FollowedId) where both are foreign keys to the Members table

Upvotes: 1

Related Questions