A
A
Alexander Evgenievich2015-10-29 18:16:27
symfony
Alexander Evgenievich, 2015-10-29 18:16:27

When is it convenient to use the EntityID field instead of additional tables?

Hello.
For example:
there is a table Notification (notifications). Notifications can be system (System), there may be notifications related to work on database entities. Accordingly, when receiving a notification, we need to find out its type, and get data based on the type.
The next question is, how would it be more correct: to create additional tables with OneToOne relationships?
notifications:

  • - id
  • - user_id
  • - created_at
  • -active
  • - type (SYSTEM_TYPE, POST_TYPE, COMMENT_TYPE ...)

NotificationSystem:
  • - id (one-to-one)
  • - data
  • - system_type

NotificationPost:
  • - id (one-to-one)
  • - post_id

NotificationComments:
  • - id (one-to-one)
  • - comment_id

-----
Either create one table for all cases with different columns:
Notifications:
  • - id
  • - user_id
  • - created_at
  • -active
  • - type (SYSTEM_TYPE, POST_TYPE, COMMENT_TYPE ...)
  • - system_type
  • - post_id
  • - comment_id
  • ...

------
Either use the EntityId:
Notifications column for additional types:
  • - id
  • - user_id
  • - created_at
  • -active
  • - type (SYSTEM_TYPE, POST_TYPE, COMMENT_TYPE ...)
  • - system_type
  • - entity_id("Post23", "Post24", "Comment12", "Comment13" ...)

I would like to know your opinion.
*I hope I spelled it right

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-29
@banderos120

you need table inheritance and different types of objects for different types of notifications. This is if you take "usually".
ps at the work with the doctrine it is easier to operate with entities and mutual relation of these instead of tables. This is a domain-centric thing, not a data-centric one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question