Question

I have 3 tables:

Post

Category

PostCategory (many to many relation table)

It works fine when user select one or more categories for the post. But one scenario is that when the user select none of the categories, what should I do to manage these uncategorized posts?

I thought of two ways, I don't know which is better.

1. Uncategorized post should not be inserted into [PostCategory].

Problems:

a) In the URL Route, I use "/Post/Category/Travel" to show categorized posts. Now the user want to list all uncatgorized posts, I can only use something like "/Post/Category/Uncategorized". This will cause many code changes in order to tell "Uncategorized" string from a normal URL Route value.

b) It will be a confusion when user himself add a category called "Uncategorized" to the system. (may be I can define some system reserved words, but I don't think it's nice.)

2. Add a constant value (Uncategorized) to [Category], also as a system reserved word. If the user select none of the categories, insert the post into PostCategory(postId, UncategorizedId).

Problems:

It regards "Uncategorized" as a category, it means a normal category to the computer, only human knows this is a special category. It is not good in OOP design.

It's hard to decide which one is better, is there any other way to manage "Uncategorized" posts?

Was it helpful?

Solution

The solution (2) would allow a single post to be both categorized and uncategorized. So purely from the data consistency standpoint, (1) is a better solution.

I can't really comment on complexity of changes in your code, but as a general guideline, when choosing between cleaner code and cleaner data, prefer cleaner data.

OTHER TIPS

Then for the sake of data consistency, indexing benefits on tags,and to preserve your own sanity, every entry must be tagged/categorized. Unless by your design or some other constraints, this is not an option. Take this very site for example. StackOverflow won't let you post a question here without a tag. You will gain performance benefits (at least) from tagging your content and indexing those tags.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top