Bogdan Zurac
Bogdan Zurac

Reputation: 6451

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 ?

Upvotes: 7

Views: 2700

Answers (1)

Duncan Walker
Duncan Walker

Reputation: 2201

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')
});

Upvotes: 10

Related Questions