例如,用户创建一个产品,并将其分配到一个类别中。
在类别中,我们有一些记录:
-phone, id:0
-computer, id:1
-pad, id:2
并且用户创建产品,产品需要分配类别,用户执行以下操作:
name:iphone
cat:0
流程将像这样工作:
1. check the cat is exist in db or not
2a. if not exist prompt error
2b. if exist, put the record in db.
但是在完成第 1 步检查之后,以及在 2b 开始之前,是否有任何机会。管理员删除电话类别。如果发生这种情况,数据库将插入一条没有 cat id watch 的记录。数据库将具有以下内容:
*-phone, id:0* (not any more, because the admin delete it)
-computer, id:1
-pad, id:2
但是有这样的记录:
name:iphone //but it belong to no category, because the admin delete it.
cat:0
如果有机会这样做,我该如何避免这种情况?谢谢你。
(使用 php 和 mysql 与 codeigniter)