Search code examples
ember.jsember-data

can i createRecord() without using save()?


I'm learning ember from the scratch and i stumbled upon something i can't quite understand:

const newNote = this.store.createRecord('note', {
    content: 'once upon a time...',
});

newNote.save().then(this._redirectToNewNote.bind(this));

Is the result of createRecord in the database before saving, or is it like a dummy object? can I use createRecord without saving?


Solution

  • Yes. you can use it without saving, do remember it will be removed from store when you refresh page.

    From ember guide

    createRecord is used for creating new records on the client side. This will return a new record in the created.uncommitted state. In order to persist this record to the backend you will need to call record.save().