I need to ‘connect’ some of my Kirby pages to table rows in a database, and need to be able to update the rows if a page is created, updated (with a new ID) or deleted.
Example: let’s say that I am creating a Blog, where I’m only going to have a few hundred articles. So, I’m happy with having my articles as flat-file Kirby Pages. But each article might potentially have hundreds or even thousands of comments. I want to make my own commenting system, but because of the sheer amount of comments, I decide it’s best to put the comments in a database. The problem is, that each comment (in the database) is ‘connected’ to an Article page. That means, that if an Article pages changes its ID, I should be able to catch that event, and update all the comments for that article in my comments table. If an Article page is deleted, I need to immediately delete all comments for that page from the database.
To make these operations simpler, in the database I create an ‘articles’ table, containing just the Article IDs. That table is then connected to the ‘comments’ table via a foreign key, with cascading updates: if I update the Article ID in the ‘articles’ table, the database automatically updates every comment related to that article. If I delete an Article from the ‘articles’ table, the deletion also cascades, and all comments are automatically deleted. I now only have to manage the ‘articles’ table. However, I STILL need to ‘catch’ the event of when an Article Page is created, updated or deleted - so that I can create/update/delete the corresponding article record in my database table.
Am I missing something obvious? How can I do this? - all guidance truly appreciated.