Reputation: 11885
i have 2 tables, user and follower.
user table. (UserId, UserName)
Follower table (Id, UserId, FollowerId) (2 foreign keys, both UserId and FollowerId are reference to UserId in User table)
User.UserId and Follower.FollowerId, I think this is one to many, one user can have many followers.
what about User.UserId and Follower.UserId, is this one to one or one to many. I think I got myself confused.
Edit:
this is many to many relationship. the way I named it confused me.
User table stays the same, Follower table changes to (Id, Leader, Follower)
now its clear, one leader can have many followers, one follower can follow many leaders.
Upvotes: 0
Views: 107
Reputation: 51052
I think your naming has gotten you confused. Don't use the same name for an entity and for a role. Really what you have is a Person table and another table that indicates a relationship between people; maybe call it the Connection table.
With this approach it becomes clear that a person can play either role in a connection, and that all of the relationships described are many-to-many.
Upvotes: 2
Reputation: 8418
just look at it from the table perspective, it is a one to many. so in implementation let's say user A in table User might have user B, C and D rows in table Follower, therefore one to many.
Upvotes: 0