Blog Data Model Tuning Guidelines
I have the following setup for my blog data model:
Blog Articles Categories
----- -------- 1 ----------
ID \ 1 * ID / ----- ID
Name \ ------------ BlogID / Name
Owner Name * /
CategoryID- /
I'm worried about how this data model fits in with "best practices" for blogs. If a blog is deleted, should all articles for that blog be deleted? If a category is deleted, what should happen to the articles?
Is there a better way? Is there something I am missing? What do "best practices" offer?
a source to share
It really depends on your use case. Many blog applications use many-to-many tags instead of one-to-many categories because it makes more sense to treat an article as referring to (possibly) many tags than viewing the article as being "contained" within a category.
If the logic behind your blog is that the article is strictly contained within a category, then a one-to-many relationship is justified. And in some cases, cascading deletion will also be warranted. After all, where would the orphaned articles exist.
This is just a case where you have to anticipate your user-based intuition. What they assume is natural.
By the way, this is a lot more work, but if it were me, I would not have done the cascading delete. I would mark articles as orphaned and hide them from most views. I would also provide some interface for recovering orphan articles. And I would consider providing a script that deletes whatever was lost for more than a specified period of time. That way, if you were wrong about what your users expected, you can fix the problem.
a source to share
This (older) post contains some of the tagging-related db schema variations, including a detailed discussion. Maybe this is a good starting point.
a source to share
If your relationship is set up correctly, you cannot delete a category without first deleting all related data. It seems odd that deleting a category would delete a bunch of articles, but at the same time, if the category is no longer valid, then the articles shouldn't be either.
Possibly an option to reassign all articles to a new category.
a source to share
A few questions. Can an article have more than one category? Do you allow an article to have 0 categories associated with them? However, from your description, I would say that you do not want to delete articles. Categories, in my experience with blog design, usually have many, many relationships with articles / posts (multiple categories describing multiple posts). So I wouldn't delete them, but once again it would depend on your business logic and how you wanted to handle it.
a source to share