Ember Data 2.3 and 2.4 Beta Released

Ember Data 2.3, a minor version release of Ember Data, is released today. This release represents the work of over 32 direct contributors, and over 196 commits.

Ember Data 2.4 beta.1, the branch of Ember Data that will be released as stable in roughly six weeks, is also being released today.

Changes in Ember Data 2.3

Ember Data 2.3 is now a full Ember CLI addon. Previous versions of Ember Data required users to include both the ember-data package in their project's package.json file and the ember-data package in their project's bower.json file. This resulted in confusion because updating ember-data in package.json would not update ember-data in bower.json .

To upgrade Ember Data to version 2.3 in your Ember CLI projects please do the following:

remove the ember-data package from your bower.json update ember-cli-shims package to version 0.1.0

1 2 3 4 5 6 7 8 9 10 ... "dependencies": { "handlebars": "2.0.0", "ember": "~2.2.0", - "ember-cli-shims": "0. 0.6 ", + "ember-cli-shims": "0. 1.0 ", "ember-cli-test-loader": "ember-cli-test-loader#0.1.3", - "ember-data": "~1.13.12", "ember-load-initializers": "ember-cli/ember-load-initializers#0.1.5", ...

Then in your package.json update ember-data to ^2.3.0

1 2 3 4 5 6 7 8 9 ... "devDependencies": { ... "ember-cli-sri": "^2.0.0", "ember-cli-uglify": "^1.2.0", - "ember-data": "^2. 2.1 ", + "ember-data": "^2. 3.0 ", "ember-disable-proxy-controllers": "^1.0.1", ...

Thanks to @fivetanley, for his heroic efforts in converting Ember Data's build to Ember CLI's addon infrastructure.

Importing Modules

The Ember Data addon allows users to import modules directly into their application instead of accessing modules top level DS namespace.

The following module paths are considered to be public API and will be supported until at least Ember Data 3.0:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 import Model from ' ember-data/model ' ; import RESTSerializer from ' ember-data/serializers/rest ' ; import JSONSerializer from ' ember-data/serializers/json ' ; import JSONAPISerializer from ' ember-data/serializers/json-api ' ; import JSONAPIAdapter from ' ember-data/adapters/json-api ' ; import RESTAdapter from ' ember-data/adapters/rest ' ; import Adapter from ' ember-data/adapter ' ; import Store from ' ember-data/store ' ; import Transform from ' ember-data/transform ' ; import attr from ' ember-data/attr ' ; import { hasMany, belongsTo } from ' ember-data/relationships ' ;

Modules that are not considered to be public API have been placed under the ember-data/-private path. Please do not import these modules into your app or test code as they may be changed or removed without warning.

Thanks to @rwjblue for implementing this module API.

Notable Bug Fixes

The EmbeddedRecordsMixin now uses keyForRelationship to generate the serialized key for embedded relationships. Thanks to @GCorbel for this fix.

The JSONAPISerializer now correctly accepts {"data": null} as a valid response instead of throwing an unhelpful error message. Thanks to @mitchlloyd for the bug report.

See the Ember Data 2.3.0 CHANGELOG for a full list of all changes.

Ember Data 2.4 beta

Ember Data 2.4 beta is released today, and in six weeks it will become the new stable version of Ember Data. This beta cycle introduces a single new feature.

Friendly Errors

@nikz has implemented RFC 101 which provides more context for RESTAdapter and JSONAPIAdapter errors in Ember Data. Be sure to check out the pull request for more details.

For more details on changes in 2.4, review the Ember Data 2.4.0-beta.1 CHANGELOG.

Upcoming Features

Two new features recently landed on the Ember Data canary branch. They each address add some long requested features to Ember Data. However, before they can be enabled in a beta branch the Ember Data team would like the community to try them out and provide feedback on their implementations. These two feature flagged features are only available on the master branch (sometimes called "canary") of Ember Data. To test them out please update the version of Ember Data in package.json to emberjs/data#master and add the feature to the EmberENV 's FEATURES object in config/environment.js .

config/environment.js 1 2 3 4 5 6 7 8 var ENV = { EmberENV : { FEATURES : { ' ds-finder-include ' : true , ' ds-references ' : true } } };

For more information you can check out Ember's feature flags guide.

ds-finder-include

The ds-finder-include feature allows an include query parameter to be specified with using store.findRecord() and store.findAll() as described in RFC 99. This should make it easier to specify when backends should return sideloaded relationships. Thanks to @HeroicEric for implementing this feature.

1 2 3 var article = this .store.findRecord( ' article ' , 1 , { include : ' comments ' });

1 2 3 var article = this .store.findAll( ' article ' , { include : ' comments ' });

ds-references

The ds-references feature implements the references API as described in RFC 57. References is a low level API to perform meta-operations on records, has-many relationships and belongs-to relationships:

get the current local data synchronously without triggering a fetch or producing a promise

notify the store that a fetch for a given record has begun, and provide a promise for its result

similarly, notify a record that a fetch for a given relationship has begun, and provide a promise for its result

retrieve server-provided metadata about a record or relationship

Consider the following post model:

app/models/post.js 1 2 3 4 5 6 7 import Model from ' ember-data/model ' ; import { belongsTo, hasMany } from ' ember-data/relationships ' ; export default Model.extend({ comments : hasMany(), author : belongsTo() });

The references API now allows the possibility to interact with the relationships:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 var post = store.peekRecord( ' post ' , 1 ); if (post.belongsTo( ' author ' ).value() !== null ) { console.log(post.get( " author.name " )); } else { var authorId = post.belongsTo( " author " ).id(); post.belongsTo( ' author ' ).load(); console.log( ` Loading author with id $ {authorId} ` ); } post.belongsTo( ' author ' ).reload(); var commentIds = post.hasMany( ' comments ' ).ids(); if (post.hasMany( ' comments ' ).value() !== null ) { var meta = post.hasMany( ' comments ' ).meta(); console.log( ` $ {commentIds.length} comments out of $ {meta.total} ` ); } else { post.hasMany( ' comments ' ).load(); } post.hasMany( ' comments ' ).reload();

Thanks to @pangratz for implementing this feature.