开发者

Best practice table scheme for active and non active field

开发者 https://www.devze.com 2023-01-31 19:54 出处:网络
i have simple table Posts id title content what is the best practice to handle with non active post 1- use the temp_posts table to move non-active posts to this table

i have simple table

Posts

id

title

content

what is the best practice to handle with non active post

1- use the temp_posts table to move non-active posts to this table

2- just set flag for post's active field

my own prefer is to use 1 solution,

cause you would not use condtion (active = 1) everytime i use find command

so what you can offer to escape of using condition (active = 开发者_Python百科1) everytime


It'd go with #2. You have the overhead of a completely separate Model and find() code with #1. If you didn't want to set tcondition = array('active' => 1) everytime, default it in the Post Model by using beforeFind(). Although the latter may not work in all cases when finding on multiple models.


I don't think it will make a lot of difference if the active field is numeric type. It will make many other operations easy. So I will go for the second one.


I don't think there is a best practice for this case, both solutions have their advantages and disadvantages, see Jason's answer.

Personally, I tend for #1, because on a conceptual level you probably have Drafts and Posts, and not Posts which are either active or inactive. It's a subtle difference, but in the first case the two models can have different attributes. For example, a Post will probably have a PublicationDate, whereas such an attribute doesn't make sense for a Draft. You can't model this by only using a Post model.

0

精彩评论

暂无评论...
验证码 换一张
取 消