Search code examples
foreign-keysdoctrine-ormsingle-table-inheritance

STI + multiple FK on one column


There are tables:

comments(id, body, object_kind(photo, topic, ...), object_id),
photos(id, title),
topics(id, title, body),
...(id, ...).

How it possible link using FK object_kind+object_id with suitable row in related tables? And create onCascade=DELETE (remove comments of topic when removing topic).

One of sollution: create separate columns to each relation type: comment_id, photo_id, but I'm trying find more flexible sollution.


Solution

  • No way. Only separate columns like comment_id, photo_id which are nullable=true