所以这个问题感觉很像我的上一个问题。Strongloop 让我觉得自己像个菜鸟。哈哈。
我从一些 LB 示例中偷了这个:
var Order = mongoDev.createModel('order', {
customerId: Number,
orderDesc: String
});
var Customer = mongoDev.createModel('customer', {
id: {type: Number, id: true},
name: String,
emails: [String],
age: Number},
{strcit: true});
//Order.belongsTo(Customer);
Order.belongsTo(Customer, {as: 'customer', foreignKey: 'customerId'});
Customer.hasMany(Order, {as: 'orders', foreignKey: 'customerId'});
在资源管理器中,我看到了客户和订单端点。客户也有端点/customers/{id}/orders
,订单有/orders/{id}/customer
等等。到目前为止一切都很好。
我有这个客户添加:
GET .../api/customers/53c599594e23e50000a41acf
{
"id": "53c599594e23e50000a41acf",
"name": "John1",
"emails": [
"john@x.com",
"jhon@y.com"
],
"age": 30
}
当我发布订单时,我得到一个空的 customerId:
POST .../api/customers/53c599594e23e50000a41acf/orders
data: {"orderDesc": "whatever"}
result:
{
"customerId": null,
"orderDesc": "whatever",
"id": "53c59d1efd31a4000062e7d8"
}
有什么想法我在这里做错了吗?