0
votes

I'm trying to develop an application using the Fixture Adapter with Ember-Data.

When I try and create a new object (based on a model I've defined), it won't work unless I specify the ID.

If I specify the ID and do this:

var person = SD.Person.createRecord({
    id: 234,
    name: "test"
});

var person.save();

I get:

Error: assertion failed: An adapter cannot assign a new id to a record that already has an id. had id: 234 and you tried to update it with 234. This likely happened because your server returned data in response to a find or update that had a different id than the one you sent.

Which makes it sound like somehow I'm updating an existing record (I'm not, there's only 2 fixtures for my Person object with ID's of 1 and 2 respectively).

Is Ember trying to save my object twice somehow?

I thought I may have to try and use generateIdForRecord to set the ID, but I can't reference that function no matter what I try.

newBooking.set('id', this.store.generateIdForRecord(this.store, newBooking));
newBooking.set('id', DS.generateIdForRecord(this.store, newBooking));
newBooking.set('id', this.generateIdForRecord(this.store, newBooking));
newBooking.set('id', generateIdForRecord(this.store, newBooking));

TypeError: this.store.generateIdForRecord is not a function

I'm using the latest releases of Ember and Ember-Data (have tried previous releases too). My model is implemented no differently to the TodoMVC tutorial in the Ember guides and in the tutorial nothing fancy needs to be done to manage ID's with the Fixture adapter so I've really no idea what's going on.

How do I create a new Person object (as per my example, just one 'name' field and persist it using Ember-Data's fixture adapter without the aforementioned errors?

1
what is SD for a namespace?intuitivepixel
@intuitivepixel - I created my app on SD. I was about to post an update on the question, but my first code snippet is actually working. For some reason I was just expecting to see it as an event in the console. The object was being created after all.Anonymous

1 Answers

1
votes

In the end, my first code snippet worked fine.

For some reason, I was expecting to see the new object being persisted in the developer console. My models were being listed in a different view so I didn't realize it was actually working as intended.