I have two tables in my database: 'stories' and 'votes'.
The stories table contains all information about an article (e.g. title, body, author name, etc.). The votes table contains all votes on all articles. There is a field in votes called item_name which contains the id of an article that a vote was cast on.
In simple words, item_name in votes is equal to id in stories (depending on which article a user voted on).
The question is: if an article gets deleted, how can I automatically delete all records in the votes table that are related to that article?
Can it be set up in the database itself, so there's no need to set up additional PHP queries?
Here is my database's structure:
stories
votes