Angularjs 环回无法通过lbServices功能将记录插入到相关模型中

Angularjs 环回无法通过lbServices功能将记录插入到相关模型中,angularjs,node.js,loopbackjs,strongloop,Angularjs,Node.js,Loopbackjs,Strongloop,我正在构建一个应用程序,使用环回作为后端,angularjs作为前端,MySql作为数据库选择。 环回版本为2.22.0,环回版本为1.5.0 有模特儿和模特儿。两者都有通过环回自动生成的“id”字段(即“idInjection”:true) 它们都是相关的,因为Person有许多Post和Post属于Person,通过Post模型中的personId列上的外键链接 假设两个表中已经有一些记录 我使用lb ng命令生成了lbServices.js文件。 所以现在当我尝试使用这个函数时 Perso

我正在构建一个应用程序,使用环回作为后端,angularjs作为前端,MySql作为数据库选择。 环回版本为2.22.0,环回版本为1.5.0

有模特儿和模特儿。两者都有通过环回自动生成的“id”字段(即
“idInjection”:true

它们都是相关的,因为
Person
有许多
Post
Post
属于
Person
,通过
Post
模型中的
personId
列上的外键链接

假设两个表中已经有一些记录

我使用lb ng命令生成了lbServices.js文件。 所以现在当我尝试使用这个函数时

Person.posts.create({               
content: "Some content",
id: $rootScope.currentUser.id
}) 
它给了我重复输入的错误

我对此进行了调查,发现这是因为lbServices.js文件中的restapiurl
“/People/:id/posts”
有一个id参数,Post模型也有一个id列,它是主键。 因此,它将id传递给它们两个,但都失败了。形成了一种模糊性

对于本例,
$rootScope.currentUser.id=1
,并且
Post
表中已经存在一行
id=1

现在,当我更改
Post
模型的属性(
“idInjection”:false
)并创建一个自定义主键列作为“uid”并自动递增时。 我可以插入

Person.posts.create({               
content: "Some content",
id: $rootScope.currentUser.id
}) 
所以我想知道我是否以正确的方式插入到相关的模型中,或者这是环回的问题?还是有更好的方法从AngularJs前端插入

我确实希望避免将每个模型的主列名更改为“id”以外的其他名称


请提供帮助。

由于id字段是自动生成的号码,您的呼叫应该是:

Person.posts.create({               
    content: "Some content",
    personId: $rootScope.currentUser.id
}) 
Person.posts.create(
{id: $rootScope.currentUser.id},
{
   content: "Some content",
   title:   "Some title"
})

我知道我做错了什么。 正确的插入方式应为:

Person.posts.create({               
    content: "Some content",
    personId: $rootScope.currentUser.id
}) 
Person.posts.create(
{id: $rootScope.currentUser.id},
{
   content: "Some content",
   title:   "Some title"
})

我尝试了这个,但得到了这个错误:
POSThttp://localhost:3000/api/People/posts 404(未找到)