Skip to content

Files

Latest commit

3fe14c5 · Apr 17, 2024

History

History
This branch is 561 commits behind emberjs/data:main.

model

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Aug 25, 2023
Apr 4, 2024
Oct 25, 2023
Jul 18, 2019
Feb 24, 2024
Apr 2, 2023
Apr 5, 2024
Mar 19, 2024
Jul 10, 2023
Mar 30, 2024
Mar 30, 2024
Apr 17, 2024
Mar 9, 2024
Oct 25, 2023

EmberData Model EmberData Model

Runtime Classes for use as a Schema Source and Resource Presentation for EmberData

Installation

Install using your javascript package manager of choice. For instance with pnpm

pnpm add @ember-data/model

Tagged Releases

  • NPM Canary Version
  • NPM Beta Version
  • NPM Stable Version
  • NPM LTS Version
  • NPM LTS 4.12 Version

Provides a Presentation Model for resource data in an EmberData Cache

This package implements the EmberData Store's instantiateRecord and teardownRecord hooks as well as configures an associated SchemaService implementation.

Models are defined as classes extending from import Model from '@ember-data/model'; and the attributes and relationships on these classes are parsed at runtime to supply static "schema" to EmberData's SchemaService.

Resource data for individual resources fetched from your API is presented to the UI via instances of the Models you define. An instantiated Model is referred to as a record.

When we refer to the ModelClass as opposed to a Model or Record we are referring specifically to the class definition and the static schema methods present on it.

When we refer to a record we refer to a specific class instance presenting the resource data for a given type and id.

Defining a Model

app/models/person.js

import Model, { attr, belongsTo, hasMany } from '@ember-data/model';

export default class PersonModel extends Model {
  @attr name;

  @belongsTo('pet', { inverse: 'owners', async: false }) dog;

  @hasMany('person', { inverse: 'friends', async: true }) friends;
}

modelName convention

By convention, the name of a given model (its type) matches the name of the file in the app/models folder and should be lowercase, singular and dasherized.