有源和无源字段的最佳实践表方案
我有简单的桌子
帖子
编号
标题
内容
处理非活动帖子的最佳做法是什么
1-使用 temp_posts 表将非活动帖子移动到该表
2-只需为帖子的活动字段设置标志,
我自己更喜欢使用 1 个解决方案,
因为每次我使用 find 命令时你不会使用条件(active = 1),
所以你可以提供什么来逃避每次使用条件(active = 1)
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 = 1) everytime
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它会与#2 一起使用。 #1 会产生完全独立的 Model 和 find() 代码的开销。如果您不想每次都设置 t
condition = array('active' => 1)
,请使用beforeFind()
在 Post 模型中默认它。尽管后者在多个模型上查找时可能并不适用于所有情况。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 usingbeforeFind()
. 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.
我认为这种情况没有最佳实践,两种解决方案都有其优点和缺点,请参阅 Jason 的回答。
就我个人而言,我倾向于#1,因为在概念层面上,您可能有
Drafts
和Posts
,而不是处于活动或非活动状态的Posts
。这是一个微妙的差异,但在第一种情况下,两个模型可以具有不同的属性。例如,Post
可能会有一个PublicationDate
,而这样的属性对于Draft
没有意义。您无法仅使用Post
模型对此进行建模。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
andPosts
, and notPosts
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, aPost
will probably have aPublicationDate
, whereas such an attribute doesn't make sense for aDraft
. You can't model this by only using aPost
model.