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.
No way. Only separate columns like comment_id
, photo_id
which are nullable=true