Node.js loopbackjs远程连接器未返回ID

Node.js loopbackjs远程连接器未返回ID,node.js,rest,loopbackjs,Node.js,Rest,Loopbackjs,我有一个nodejs应用程序,它正试图与环回服务器通信 我有以下数据源 { "db": { "name": "db", "connector": "memory" }, "remoteDS": { "url": "http://localhost:3033/api", "name": "remoteDS", "connector": "remote" } } 使用环回连接器远程 我有

我有一个nodejs应用程序,它正试图与环回服务器通信

我有以下数据源

{
    "db": {
        "name": "db",
        "connector": "memory"
    },
    "remoteDS": {
        "url": "http://localhost:3033/api",
        "name": "remoteDS",
        "connector": "remote"
    }
}
使用环回连接器远程

我有
common/models/pack.json

{
    "name": "pack",
    "plural": "packs",
    "base": "PersistedModel",
    "idInjection": true,
    "properties": {},
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": {}
}
{
    "name": "pack",
    "plural": "packs",
    "base": "PersistedModel",
    "idInjection": false,
    "properties": {
        "id": {
            "type": "String",
            "id": 1
        }
    },
    "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": true,
    "properties": {},
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": {}
}
{
    "name": "pack",
    "plural": "packs",
    "base": "PersistedModel",
    "idInjection": false,
    "properties": {
        "id": {
            "type": "String",
            "id": 1
        }
    },
    "validations": [],
    "relations": {},
    "acls": [],
    "methods": {}
}
循环,因此它可能试图在创建时解析您的Id值。也许REST连接器正在创建并查询它

默认情况下,如果未定义ID属性且idInjection属性为true(或者未设置,因为默认为true),则环回会自动将ID属性添加到模型中,如下所示:

id:{type:Number,generated:true,id:true}


您不是只使用
foo
属性创建一个实例吗<代码>app.models.Pack.create({foo:'bar'})@falinsky这只是一个测试,id在数据库中自动生成,但不会返回。我相信您应该提供更多代码。例如,您如何声明您的模型
Pack
?这是在
common/models/Pack.json
中,谢谢