loopbackjs 远程连接器不返回 id
loopbackjs remote connector not returning ids
我有一个 nodejs 应用程序正在尝试与环回服务器通信
我有以下数据源
{
"db": {
"name": "db",
"connector": "memory"
},
"remoteDS": {
"url": "http://localhost:3033/api",
"name": "remoteDS",
"connector": "remote"
}
}
使用loopback-connector-remote
我有common/models/pack.json
{
"name": "pack",
"plural": "packs",
"base": "PersistedModel",
"idInjection": true,
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
和我的test.js
var app = require('./client/client');
app.models.Pack.create({foo: 'bar'})
.then(result => {
console.log(result); // { foo: 'bar', id: NaN }
return app.models.Pack.find()
})
.then(result => {
console.log(result); // [{ foo: 'bar', id: NaN }]
})
.catch(err => {
console.error(err.message);
})
不知道为什么id: NaN
当我尝试通过 api 资源管理器时,我有 id
[
{
"foo": "bar",
"id": "5bdaf67aed811700149e4549"
}
]
尝试用作您的 common/models/pack.json
{
"name": "pack",
"plural": "packs",
"base": "PersistedModel",
"idInjection": false,
"properties": {
"id": {
"type": "String",
"id": 1
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
环回 adds the id property as a number,因此它可能会尝试在创建时解析您的 Id 值。也许 REST 连接器正在创建并查询它?
By default, if no ID properties are defined and the idInjection property is true (or is not set, since true is the default), LoopBack automatically adds an id property to the model as follows:
id: {type: Number, generated: true, id: true}
我有一个 nodejs 应用程序正在尝试与环回服务器通信
我有以下数据源
{
"db": {
"name": "db",
"connector": "memory"
},
"remoteDS": {
"url": "http://localhost:3033/api",
"name": "remoteDS",
"connector": "remote"
}
}
使用loopback-connector-remote
我有common/models/pack.json
{
"name": "pack",
"plural": "packs",
"base": "PersistedModel",
"idInjection": true,
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
和我的test.js
var app = require('./client/client');
app.models.Pack.create({foo: 'bar'})
.then(result => {
console.log(result); // { foo: 'bar', id: NaN }
return app.models.Pack.find()
})
.then(result => {
console.log(result); // [{ foo: 'bar', id: NaN }]
})
.catch(err => {
console.error(err.message);
})
不知道为什么id: NaN
当我尝试通过 api 资源管理器时,我有 id
[
{
"foo": "bar",
"id": "5bdaf67aed811700149e4549"
}
]
尝试用作您的 common/models/pack.json
{
"name": "pack",
"plural": "packs",
"base": "PersistedModel",
"idInjection": false,
"properties": {
"id": {
"type": "String",
"id": 1
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
环回 adds the id property as a number,因此它可能会尝试在创建时解析您的 Id 值。也许 REST 连接器正在创建并查询它?
By default, if no ID properties are defined and the idInjection property is true (or is not set, since true is the default), LoopBack automatically adds an id property to the model as follows:
id: {type: Number, generated: true, id: true}