使用默认JsonApiSerializer and Adapter
但与DS.EmbeddedRecordsMixin
结合使用时,应该如何在执行POST以创建新记录或使用PATCH更新现有记录时查看服务器的响应,以包含{{ 1}}请求中的关系。
这很重要,因为Ember Data使用响应在创建后将Id分配给记录,并更改其状态。
考虑以下请求,其中发票与2个发票行一起创建。
hasMany
在正常的GET请求中,Json Api在{
"data": {
"type": "sales-invoices",
"attributes": {
"name": null,
"net-price": 29,
"vat-amount": 6.09,
"gross-price": 35.09
},
"relationships": {
"customer": {
"data": {
"type": "companies",
"id": "131"
}
},
"organization": {
"data": {
"type": "organizations",
"id": "3"
}
}
},
"sales-invoice-lines": [
{
"data": {
"attributes": {
"name": "Basic Linux Hosting",
"sort": 0,
"unit-price": 9,
"quantity": 1,
"total": 9,
"net-price": 9,
"vat-amount": 1.89,
"gross-price": 10.89,
"created": null,
"changed": null
},
"relationships": {
"sales-invoice": {
"data": {
"type": "sales-invoices",
"id": null
}
},
"vat-rate": {
"data": {
"type": "vat-rates",
"id": "1"
}
}
},
"type": "sales-invoice-lines"
}
},
{
"data": {
"attributes": {
"name": "Extra .com domain",
"sort": 1,
"unit-price": 20,
"quantity": 1,
"total": 20,
"net-price": 20,
"vat-amount": 4.2,
"gross-price": 24.2,
"created": null,
"changed": null
},
"relationships": {
"sales-invoice": {
"data": {
"type": "sales-invoices",
"id": null
}
},
"vat-rate": {
"data": {
"type": "vat-rates",
"id": "1"
}
}
},
"type": "sales-invoice-lines"
}
}
]
}
}
哈希中包含单独的发票行(请参阅规范链接)。
对于嵌入式记录,来自POST或PATCH的响应是否应包含所包含哈希中的记录,或者(在这种情况下)销售发票行哈希中的记录?
答案 0 :(得分:0)
我担心在使用JSONAPIAdapter / Serializer时不支持EmbeddedRecord。您需要通过包含的哈希来执行嵌入式有效负载。