I’m using can.Model to retrieve data by id:
Invoice = can.Model({
findAll: 'GET /invoices',
create : "POST /invoices",
update : "PUT /invoices/{id}",
destroy : "DELETE /invoices/{id}"
},{});
When navigating to /invoices, the result is as expected, like:
[
0: {
"ID": "1",
"Client": "Client1",
},
1: {
"ID": "2",
"Client": "Client2"
}
]
However, the data retrieved with Invoice.findAll and logged to the console, it looks like this, with the same data item repeated for each element in the list:
[
0: {
"ID": "1",
"Client": "Client1"
},
1: {
"ID": "1",
"Client": "Client1"
}
]
The response from the server is correct, so why is it being interpreted as a list of identical items?
When data has an id field different from
id, it should be specified using theidfield. For instance, as mentioned in the documentation forcan.Modelin.NETit is common to useId. In this case, the id field must be defined asID: