0

I've facing a trouble, and i need your help please:

If we assume is that there is a table called page has and id, name, and creation_date.

Also if there's another table called user has and id, name, birthdate.

Also if there's another table called admin has and id, name, is_super_admin

The last table is post has writer and content.

The problem is that: the post write can be an page or an user or an admin. So how can i set the post.writer column as foreign key from all of (page.id, user.id and admin.id). How can the database define is that for example [writer = "1"] refers for a an page, admin or an user?

Belo Beem
  • 33
  • 5

1 Answers1

0

Your common elements are id and name between page, user and admin. The "is_super_admin" is a property of an admin level user, and the property "birthdate" belongs to "users", and "creation_date" belongs to pages. One can make the argument that "birthdate" and "creation_date" are synonymous. Assemble your common elements into a single entities table and use additional child tables to hold the unique properties. Define your table schema based on the data, not the real world objects being represented.

Chris Caviness
  • 586
  • 3
  • 10