Sails.js 在Sails JS响应中看不到Id
因此,我正在摆弄SailsJS,试图让API启动并快速运行。我还没有设置数据存储(可能会使用mongodb),但我看到了我假设的类似于SQLite数据库之类的东西。所以我为用户生成了一个模型和控制器。所以在浏览器中我点击了user/create。我看到createdAt和updatedAt,但没有Id。我需要真实的数据存储才能看到Id吗?这还是免费的吗 适配器Sails.js 在Sails JS响应中看不到Id,sails.js,Sails.js,因此,我正在摆弄SailsJS,试图让API启动并快速运行。我还没有设置数据存储(可能会使用mongodb),但我看到了我假设的类似于SQLite数据库之类的东西。所以我为用户生成了一个模型和控制器。所以在浏览器中我点击了user/create。我看到createdAt和updatedAt,但没有Id。我需要真实的数据存储才能看到Id吗?这还是免费的吗 适配器 // Configure installed adapters // If you define an attribute in you
// Configure installed adapters
// If you define an attribute in your model definition,
// it will override anything from this global config.
module.exports.adapters = {
// If you leave the adapter config unspecified
// in a model definition, 'default' will be used.
'default': 'disk',
// In-memory adapter for DEVELOPMENT ONLY
// (data is NOT preserved when the server shuts down)
memory: {
module: 'sails-dirty',
inMemory: true
},
// Persistent adapter for DEVELOPMENT ONLY
// (data IS preserved when the server shuts down)
// PLEASE NOTE: disk adapter not compatible with node v0.10.0 currently
// because of limitations in node-dirty
// See https://github.com/felixge/node-dirty/issues/34
disk: {
module: 'sails-dirty',
filePath: './.tmp/dirty.db',
inMemory: false
},
// MySQL is the world's most popular relational database.
// Learn more: http://en.wikipedia.org/wiki/MySQL
mysql: {
module : 'sails-mysql',
host : 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',
user : 'YOUR_MYSQL_USER',
password : 'YOUR_MYSQL_PASSWORD',
database : 'YOUR_MYSQL_DB'
}
};
模型
执行
../user/findAll
以列出所有用户。每个用户都应该有一个“id”属性,例如
{
"username":"admin",
"password":"$2a$10$SP/hWtlJINkMgkAuAc9bxO1iWsvVcglwEU4ctGCiYpx.7ykaFWt56",
"createdAt":"2013-07-12T17:36:29.852Z",
"updatedAt":"2013-07-12T17:36:29.852Z",
"id":1
}
它们会删除findAll,您只需使用find instad即可
您也可以这样请求我已经通过在同一个sails应用程序中的不同DB之间切换来检查它,并且它的工作绝对正常 因此,在这种情况下,您可以向模型中添加autoPK属性并将其设置为true,如下所示:
module.exports = {
attribute:{
//your model attributes with validations.
},
autoPK:true
}
如果这对您不起作用,那么我认为您在系统上安装的sails副本有问题
请尝试使用npm安装较新版本(v0.9.8)的sails,或尝试使用较新版本(v0.9.8)的详细信息更新package.json并执行npm安装。未看到它。下面是我所看到的一切<代码>[{firstName:“Chad”,“createdAt:“2013-07-12T04:13:16.917Z”,“updatedAt:“2013-07-12T04:13:16.917Z”},{“firstName:“Chad”,“lastName:“Hietala”,“createdAt:“2013-07-12T04:13:33:33.538Z”,“updatedAt:“2013-07-07-12T04:13:33.538Z”,“updatedAt:”2013-07-07-12T04:15:44.243:“createdAt:”2013-07-07-12T04:43:“createdAt:”,“updatedAt”:“2013-07-12T04:15:47.704Z”},{“createdAt”:“2013-07-12T04:16:15.506Z”,“updatedAt”:“2013-07-12T04:16:15.506Z”}]/config/adapters.js配置使用的数据库。我得到一个“id”属性,其中包含“default:“disk”和“default:”内存"'. 你能发布你的/config/adapters.js和/api/models.User.js吗?还有:…/User/find/1会显示第一个用户吗?再试试看。用这些文件更新了我的帖子。当我尝试使用id查找特定用户时,我会得到一个
未找到的meesage。我有相同的adapter.js,user.js也可以。我使用的是最新版本的sails 0.8.94(出现在船上的电梯下)。您是否正在使用0.9开发版本?请尝试将其添加到您的模型中<代码>自动转帐:正确,
module.exports = {
attribute:{
//your model attributes with validations.
},
autoPK:true
}