mysql - creating social network relationship table -


hi guys need in creating relationship table. needs

enter image description here

user_one_id , user_two_id foreign key user table, status show current relationship status (0 pending, 1 friends, 2 declined, 3 blocked) , action_user_id id of user has make recent update on status field. avoid duplicate, have add unique on user_one_id , user_two_id. want user_one_id always smaller than user_two_id. stuck. here have come far

create table if not exists relationship ( user_one_id not null, user_two_id not null, status enum ('0','1','2','3') not null, action_user_id not null, unique (user_one_id, user_two_id)) 

i'll give example achieve on insert level.

set @id_one = 10; set @id_two = 20; insert relationship (user_one_id, user_two_id, status, action_user_id) values (     (case          when @id_one >= @id_two @id_two         else  @id_one     end),     (case          when @id_one >= @id_two @id_one         else  @id_two     end),     0,  <--- need set 1     10  <--- need set 1 ); 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -