1

I am learning UML to model a database for a class project. Essentially the database is for a social network. The tables are user, friends, profile, status, wall_posts, and comments. I'm having some trouble nailing down the exact relationships.

At first glance it appears that all tables have the composition relationship (of varying multiplicity); a user "has a" profile(1-1), a user "has" friends(1-0..*), wall_posts (1-0..*), and a wall_post "has" comments(1-0..*). If the user is removed, the effect cascades and should remove any records that have that user id. The user table has info like the uid's name (which is not replicated in the wall_posts table), so something like a message record would have to be removed.

Is there a flaw in my logic?

mr_bond
  • 95
  • 4

1 Answers1

2

The part where a user "has" friends(1-0..*) is flawed.

That should be an n-m between the user table and itself (or 0..*-0..* in UML notation), because all those friends are not exclusive to one user. Everybody (hopefully) can have many friends. Could be implemented by a friendship table that holds two (distinct) foreign keys to the user table and possibly additional attributes describing the relationship.

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
  • The way it is implemented the friends table is essentially the friendship table(I should switch the name). It contains the two foreign keys(f_uid, with_uid) and a since_date attribute. What is the relationship type to user in this case? Is it still composition? A friendship exists only between two people, but a user can have many of them.(2-n?) – mr_bond Mar 11 '12 at 02:33
  • @Ch0b0: the relationship between `user` and `friendship` would be `1-0..*` and there would be *two* of these connections. – Erwin Brandstetter Mar 11 '12 at 02:40