Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: Assertion Failed: You may not set `id` as an attribute on your model

Entire 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 REST API:

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

Question: How can I move around the above error ?

like image 707
Bogdan Zurac Avatar asked Jul 03 '14 16:07

Bogdan Zurac


1 Answers

Just leave out the id attribute from your DS.Model. Ember-data automatically handles that for you. You'll still be able to find the record using the id, and it'll be a property on the object when you access it from within your Ember application. See here and here for more info.

App.Plan = DS.Model.extend({
  name: DS.attr('string'),
  period: DS.attr('number'),
  price: DS.attr('number')
});
like image 191
Duncan Walker Avatar answered Sep 20 '22 07:09

Duncan Walker