I have a demand that is probably the case:
There is an article table and a category table, and the article table has a CAT_ID association category table. Here, the MySQL layer does not have a foreign key constraint. In this case, every time you create an article table, what do you usually do with this cat_id?
Some of my options:
1, to check the category table, if this category does not exist, do not let the update. (optimized: If the number of categories is not much, put in memory directly, or use the cache)
2, do not take care of this category has not existed.
Update:
1, is to do a forum system, users can publish articles, and the category is mainly by the operation of the people to create.
Reply content:
I have a demand that is probably the case:
There is an article table and a category table, and the article table has a CAT_ID association category table. Here, the MySQL layer does not have a foreign key constraint. In this case, every time you create an article table, what do you usually do with this cat_id?
Some of my options:
1, to check the category table, if this category does not exist, do not let the update. (optimized: If the number of categories is not much, put in memory directly, or use the cache)
2, do not take care of this category has not existed.
Update:
1, is to do a forum system, users can publish articles, and the category is mainly by the operation of the people to create.
I usually use the second kind of direct neglect
If the rigor of the data on the business requirements are high, of course, the first
If the requirements are not very high, the second one is fine.
First, when you save to the library, the previous business will generally ensure that the ID is active and traceable;
Again even if this ID corresponds to the category does not exist or later this category is deleted do not do cascade Delete, the final effect is only in the query this category is not found data, usually and the ID empty effect close
As your first option, check the category table, the categories are generally not too large, you can use the cache
1. Check the category table if not, the key value is inserted into the 0
article
2. When displaying the uncategorized category (i.e., the key value 0
of the article)