store.createRecord()

Creates a new unsaved record instance in the store.

Since Ember 4/5 (Octane) Spec ↗

Syntax

store.createRecord(type, properties?): Model

Parameters

NameTypeRequiredDescription
type string No The model name.
properties object No Initial attribute and relationship values.

Returns

Model — A new record with isNew true until saved.

Examples

import Component from '@glimmer/component';
import { service } from '@ember/service';
import { action } from '@ember/object';

export default class NewPostComponent extends Component {
  @service store;

  @action
  async create(title) {
    const post = this.store.createRecord('post', { title });
    await post.save();
  }
}

Notes

The record exists only in the client cache until save() persists it. Call rollbackAttributes() or unloadRecord() to discard an unsaved record (for example when a creation form is cancelled).