home
  • Blog
  • Home
  • Projects
    • Ember
    • EmberData
    • Ember CLI
4.12
  • Packages
    • @ember-data/adapter
    • @ember-data/adapter/error
    • @ember-data/adapter/json-api
    • @ember-data/adapter/rest
    • @ember-data/canary-features
    • @ember-data/debug
    • @ember-data/deprecations
    • @ember-data/experimental-preview-types
    • @ember-data/graph
    • @ember-data/json-api
    • @ember-data/legacy-compat
    • @ember-data/model
    • @ember-data/request
    • @ember-data/request/fetch
    • @ember-data/serializer
    • @ember-data/serializer/json
    • @ember-data/serializer/json-api
    • @ember-data/serializer/rest
    • @ember-data/store
    • @ember-data/tracking
  • Classes
    • <Interface> Adapter
    • <Interface> Cache
    • <Interface> Handler
    • <Interface> Serializer
    • AbortError
    • Adapter
    • AdapterError
    • BelongsToReference
    • BooleanTransform
    • BuildURLMixin
    • Cache
    • CacheManager
    • CacheStoreWrapper
    • CanaryFeatureFlags
    • ConflictError
    • CurrentDeprecations
    • DateTransform
    • DebugLogging
    • EmbeddedRecordsMixin
    • Errors
    • Fetch
    • ForbiddenError
    • Future
    • HasManyReference
    • IdentifierCache
    • InvalidError
    • JSONAPIAdapter
    • JSONAPISerializer
    • JSONSerializer
    • ManyArray
    • Model
    • NotFoundError
    • NotificationManager
    • NumberTransform
    • PromiseArray
    • PromiseManyArray
    • PromiseObject
    • RESTAdapter
    • RESTSerializer
    • RecordArray
    • RecordReference
    • RequestManager
    • RequestStateService
    • SchemaService
    • Serializer
    • ServerError
    • Snapshot
    • SnapshotRecordArray
    • StableRecordIdentifier
    • Store
    • StringTransform
    • TimeoutError
    • Transform
    • UnauthorizedError

Class Snapshot public


Defined in: ../legacy-compat/src/legacy-network-handler/snapshot.ts:24
Module: @ember-data/store

Snapshot is not directly instantiable. Instances are provided to a consuming application's adapters and serializers for certain requests.

Snapshots are only available when using @ember-data/legacy-compat for legacy compatibility with adapters and serializers.


Methods

attr (keyName) : Object public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:192

keyName
String
returns
Object

The attribute value or undefined

Returns the value of an attribute.

Example

// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
postSnapshot.attr('author'); // => 'Tomster'
postSnapshot.attr('title'); // => 'Ember.js rocks'

Note: Values are loaded eagerly and cached when the snapshot is created.

attributes : Object public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:217

returns
Object

All attributes of the current snapshot

Returns all attributes and their corresponding values.

Example

// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
postSnapshot.attributes(); // => { author: 'Tomster', title: 'Ember.js rocks' }

belongsTo (keyName, options) : (Snapshot|String|null|undefined) public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:266

keyName
String
options
Object
returns
(Snapshot|String|null|undefined)

A snapshot or ID of a known relationship or null if the relationship is known but unset. undefined will be returned if the contents of the relationship is unknown.

Returns the current value of a belongsTo relationship.

belongsTo takes an optional hash of options as a second parameter, currently supported options are:

  • id: set to true if you only want the ID of the related record to be returned.

Example

// store.push('post', { id: 1, title: 'Hello World' });
// store.createRecord('comment', { body: 'Lorem ipsum', post: post });
commentSnapshot.belongsTo('post'); // => Snapshot
commentSnapshot.belongsTo('post', { id: true }); // => '1'

// store.push('comment', { id: 1, body: 'Lorem ipsum' });
commentSnapshot.belongsTo('post'); // => undefined

Calling belongsTo will return a new Snapshot as long as there's any known data for the relationship available, such as an ID. If the relationship is known but unset, belongsTo will return null. If the contents of the relationship is unknown belongsTo will return undefined.

Note: Relationships are loaded lazily and cached upon first access.

changedAttributes : Object public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:235

returns
Object

All changed attributes of the current snapshot

Returns all changed attributes and their old and new values.

Example

// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
postModel.set('title', 'Ember.js rocks!');
postSnapshot.changedAttributes(); // => { title: ['Ember.js rocks', 'Ember.js rocks!'] }

eachAttribute (callback, binding) public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:486

callback
Function

the callback to execute

binding
Object

the value to which the callback's this should be bound

Iterates through all the attributes of the model, calling the passed function on each attribute.

Example

snapshot.eachAttribute(function(name, meta) {
  // ...
});

eachRelationship (callback, binding) public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:510

callback
Function

the callback to execute

binding
Object

the value to which the callback's this should be bound

Iterates through all the relationships of the model, calling the passed function on each relationship.

Example

snapshot.eachRelationship(function(name, relationship) {
  // ...
});

hasMany (keyName, options) : (Array|undefined) public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:379

keyName
String
options
Object
returns
(Array|undefined)

An array of snapshots or IDs of a known relationship or an empty array if the relationship is known but unset. undefined will be returned if the contents of the relationship is unknown.

Returns the current value of a hasMany relationship.

hasMany takes an optional hash of options as a second parameter, currently supported options are:

  • ids: set to true if you only want the IDs of the related records to be returned.

Example

// store.push('post', { id: 1, title: 'Hello World', comments: [2, 3] });
postSnapshot.hasMany('comments'); // => [Snapshot, Snapshot]
postSnapshot.hasMany('comments', { ids: true }); // => ['2', '3']

// store.push('post', { id: 1, title: 'Hello World' });
postSnapshot.hasMany('comments'); // => undefined

Note: Relationships are loaded lazily and cached upon first access.

serialize (options) : Object public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:534

options
Object
returns
Object

an object whose values are primitive JSON values only

Serializes the snapshot using the serializer for the model.

Example

app/adapters/application.js
import Adapter from '@ember-data/adapter';

export default Adapter.extend({
  createRecord(store, type, snapshot) {
    let data = snapshot.serialize({ includeId: true });
    let url = `/${type.modelName}`;

    return fetch(url, {
      method: 'POST',
      body: data,
    }).then((response) => response.json())
  }
});

Properties

adapterOptions public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:106

A hash of adapter options

id public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:90

The id of the snapshot's underlying record

Example

// store.push('post', { id: 1, author: 'Tomster', title: 'Ember.js rocks' });
postSnapshot.id; // => '1'

identifier public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:70

The unique RecordIdentifier associated with this Snapshot.

include public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:114

If include was passed to the options hash for the request, the value would be available here.

modelName public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:124

The name of the type of the underlying record for this snapshot, as a string.

record public

Module: @ember-data/store

Defined in ../packages/legacy-compat/src/legacy-network-handler/snapshot.ts:140

The underlying record for this snapshot. Can be used to access methods and properties defined on the record.

Example

let json = snapshot.record.toJSON();
On this page


Methods

  • attr
  • attributes
  • belongsTo
  • changedAttributes
  • eachAttribute
  • eachRelationship
  • hasMany
  • serialize

Properties

  • adapterOptions
  • id
  • identifier
  • include
  • modelName
  • record
Team Sponsors Security Legal Branding Community Guidelines
Twitter GitHub Discord Mastodon

If you want help you can contact us by email, open an issue, or get realtime help by joining the Ember Discord.

© Copyright 2025 - Tilde Inc.
Ember.js is free, open source and always will be.


Ember is generously supported by
blue Created with Sketch.