store.createRecord()
Creates a new unsaved record instance in the store.
Syntax
store.createRecord(type, properties?): Model Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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).