Collection error: statement failed: you cannot set `id` as an attribute of your model

Full error:

Uncaught Error: Assertion Failed: You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from App.Plan 

Ember Model:

 App.Plan = DS.Model.extend({ id: DS.attr('number'), name: DS.attr('string'), period: DS.attr('number'), price: DS.attr('number') }); 

Data coming from the REST API:

 {"plans":[{"id":1,"name":"Monthly subscription","period":1,"price":2}]} 

Question: How can I navigate the above error?

+7
ember-data
source share
1 answer

Just leave the id attribute from your DS.Model . Ember-data automatically processes this for you. You can still find the record using the identifier, and this will be the property of the object when you access it from your Ember application. see here and here for more information.

 App.Plan = DS.Model.extend({ name: DS.attr('string'), period: DS.attr('number'), price: DS.attr('number') }); 
+9
source share

All Articles