sailsjs 中出现 sailsjs 1.0 模型属性类型日期列类型日期时间错误

sailsjs 1.0 model attribute type date columntype datetime error out in sailsjs

在 sailsjs 1.0@beta 中,我有一个模型链接到 mysql table 中的一个视图,带有 mysql-sails@beta 适配器。

模型配置如下:

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

尽管每当我查询模型时,sails 都会在每个日期列显示大量错误:

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 它是只读的模型视图?

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

上找到了关于此的票证

修复了使用 ref 而不是字符串的日期时间问题:

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

解决方法可能是当前在用户模型中的 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
    },

然后在 UI 中,您可以轻松地将其转换为人类可读的格式,例如,执行以下操作:

new Date(user.lastSeenAt)