sailsjs 1.0模型属性类型日期columntype日期时间错误输出sailsjs

时间:2017-10-09 07:30:31

标签: mysql datetime model sails.js

在sailsjs 1.0@beta我有一个模型链接到mysql表中的视图与mysql-sails @ beta adapter。

模型的配置方式如下:

attributes: {
    id: {type:'number',  required: true},
    'release_date': { type: 'string', columnType: 'datetime' }
  }

虽然我查询模型时,风帆会在每个日期列中显示错误墙:

Warning: After transforming columnNames back to attribute names, a record
in the result has a value with an unexpected data type for property `release_date`.
The corresponding attribute declares `type: 'string'` but instead
of that, the actual value is:
```
2016-04-07T05:00:00.000Z
```

我尝试将类型设置为“datetime”,但不再支持它。

The type "datetime" is no longer supported.  To use this type in your model, change
`type` to one of the supported types and set the `columnType` property to a column 
type supported by the model's adapter, e.g. { type: 'string', columnType: 'datetime' }

我无法找到任何关于告诉sailsjs模型它的日期的正确方法的文档,以便sailsjs 1.0b不会出错,并且有办法告诉sails它是一个只读的模型视图?

2 个答案:

答案 0 :(得分:9)

经过多次挖掘后,在https://github.com/balderdashy/waterline/issues/1497

上找到了相关票据

使用ref代替字符串的日期时间问题的修复:

inspect(data.corpus1[1:2])
# <<SimpleCorpus>>
# Metadata:  corpus specific: 1, document level (indexed): 0
# Content:  documents: 2
# 
# [1] $rprx  loading    mid .60's, think    potential. 12m vol  fri  already 11m today   
# [2]  members report success  see track record  $itek $rprx $nete $cnet $zn $cwbr $inpx 

removePunctWords <- function(x) {
  gsub(pattern = "\\$", "", x)
}
data.corpus1 <- 
  tm_map(data.corpus1, 
         content_transformer(removePunctWords))
inspect(data.corpus1[1:2])
# <<SimpleCorpus>>
# Metadata:  corpus specific: 1, document level (indexed): 0
# Content:  documents: 2
# 
# [1] rprx  loading    mid .60's, think    potential. 12m vol  fri  already 11m today 
# [2]  members report success  see track record  itek rprx nete cnet zn cwbr inpx

答案 1 :(得分:0)

一种解决方法可能是当前在用户模型中的SailsJS默认Web应用程序中找到的方法:

lastSeenAt: {
      type: 'number',
      description: 'A JS timestamp (epoch ms) representing the moment at which this user most recently interacted with the backend while logged in (or 0 if they have not interacted with the backend at all yet).',
      example: 1502844074211
    },

然后在用户界面中,您可以通过执行以下操作轻松地将其转换为人类可读的格式:

new Date(user.lastSeenAt)