简体   繁体   中英

Friends table for a social network website

Now i am working on a social network website and i already built the friends table for this website but i need some suggestion before i moved forward.

I have a user table where user_id is the primary field.

So for friends i made a friends table with fields like

friend1 , friend2 , is_active

what i do actually when user1 send a friend request to user2 then at that moment i insert the two rows into the friends table like

1- friend1->user1,friend2->user2,inactive
2- friend1->user2,friend2->user1,inactive

So when somebody accept the friend request at that moment i made the both rows as active.

I made this two entries as i want whenever one user block another then easily made that corresponding row belongs to that user will be inactive.

And if a user remove the user then at that time i delete the both entries.

So please i need some suggestion regarding this please help me out to solve this asap.

I need to know is there any other way which will be more optimized than this and giving proper result.

I think that Friends_table with

User_id1, User_id2 and Rleationship_id

is easier, index on both first and second column. relationship id will be 1 - id1 request, 2- id2 request, 3 - friends, 4- id1 blocked, 5 - id2 blocked...

just an idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM