CanJS Model findAll returns a list of duplicate items

I am using can.Model to retrieve data using id :

 Invoice = can.Model({ findAll: 'GET /invoices', create : "POST /invoices", update : "PUT /invoices/{id}", destroy : "DELETE /invoices/{id}" },{}); 

When switching to /invoices result will be as expected, for example:

 [ 0: { "ID": "1", "Client": "Client1", }, 1: { "ID": "2", "Client": "Client2" } ] 

However, the data obtained using Invoice.findAll and registered on the console is as follows: one data item is repeated for each item in the list:

 [ 0: { "ID": "1", "Client": "Client1" }, 1: { "ID": "1", "Client": "Client1" } ] 

The answer from the server is correct, so why is it interpreted as a list of identical elements?

+4
source share
1 answer

When data has an id field other than id , it should be specified using the id field. For example, as stated in the documentation for can.Model in .NET , id is usually used. In this case, the id field should be defined as id :

 Invoice = can.Model({ id: 'ID', findAll: 'GET /invoices', create : "POST /invoices", update : "PUT /invoices/{id}", destroy : "DELETE /invoices/{id}" },{}); 
+5
source

All Articles