简体   繁体   English

哪一种是created_at和Updated_at列的最佳策略

[英]Which one is the best strategy for created_at and updated_at columns

Which one is the best strategy for created_at and updated_at columns on Rails? Rails中created_at和updated_at列的最佳策略是哪一种?

Datetime or Timespan? 日期时间或时间跨度? NULL or NOT NULL? 是NULL还是NOT NULL? DEFAULTS? 默认值?

I try to googling some about this but I found nothing. 我尝试对此进行谷歌搜索,但一无所获。

You've kinda answered your own question, though I think to some extent this is opinion based and not a good fit for SO.. 您已经回答了您自己的问题,尽管我认为在某种程度上这是基于观点的,而不适合SO。

created/updated "at", is a point in time, not a range of time.. hence it should be a datetime, not a timespan 创建/更新的“时间”是时间点,而不是时间范围。因此,它应该是日期时间,而不是时间跨度

Whether or not you null the updatedat with a new row, or set it the same as createdat, is a decision for you alone. 是否用新行将updateat null设置为空,还是将其设置为createdat,都是您一个人的决定。 Most of the time I see it set to a value, as it removes the headache of dealing with nulls 大多数时候,我会看到它设置为一个值,因为它消除了处理null的麻烦

Createdat can be defaulted to the database server clock time, unless you really need it done in the front end; 除非您确实需要在前端完成,否则Createdat可以默认为数据库服务器时钟时间。 it's easy to do as part of a table def, can be overridden by the front end if needed, but ensures that setting it is not forgotten by a front end oversight 它很容易作为表def的一部分进行操作,可以在需要时被前端覆盖,但要确保设置不会被前端监督遗忘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM