

























Ember Data 2.6, a minor version release of Ember Data, is released. This release represents the work of over 22 direct contributors, and over 85 commits.
Ember Data 2.7 beta.1, the branch of Ember Data that will be released as stable in roughly six weeks, is also being released.
ds-serialize-ids-and-typesEnables a new ids-and-type strategy (in addition to the already existing ids and records) for
serializing has many relationships using the DS.EmbeddedRecordsMixin that will include both
id and type of each model as an object.
For instance, if a user has many pets, which is a polymorphic relationship, the generated payload would be:
{
"user": {
"id": "1"
"name": "Bertin Osborne",
"pets": [
{ "id": "1", "type": "Cat" },
{ "id": "2", "type": "Parrot"}
]
}
}
This is particularly useful for polymorphic relationships not backed by STI when just including the id of the records is not enough.
Thanks to @cibernox for implementing this feature.
ds-boolean-transform-allow-null #4022Allow null/undefined values for boolean attributes via attr('boolean', { allowNull: true })
// app/models/user.js
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
email: attr('string'),
username: attr('string'),
wantsWeeklyEmail: attr('boolean', { allowNull: true })
});
ds-improved-ajax #3099Though ajax() (and ajaxOptions()) of DS.RESTAdapter are marked as
private, they have been overwritten in many applications, since there is
currently no other way to customize the request.
This feature adds new public methods to DS.RESTAdapter, which allow to
customize the properties of a request:
methodForRequest to get the HTTP verburlForRequest to get the URLheadersForRequest to get the headersdataForRequest to get the data (query params or request body)The params hash passed to those methods has all the properties with
which the corresponding find, createRecord, findQuery, … calls
have been invoked: store, type, snapshot(s), id(s) and query. The
requestType property indicates which method is requested; the possible
values are:
createRecordupdateRecorddeleteRecordqueryqueryRecordfindRecordfindAllfindManyfindHasManyfindBelongsToPerforming the actual AJAX request is handled by the makeRequest
method, which is similar to the existing ajax method: it makes the
request using jQuery.ajax and attaches success and failure handlers.
Say your API handles creation of resources via PUT, this can now be customized as follows:
// adapters/application.js
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
methodForRequest(params) {
if (params.requestType === 'createRecord') {
return "PUT";
}
return this._super(...arguments);
}
});
Thanks to @pangratz for implementing this feature.
ds-links-in-record-array #4263This feature exposes a links object on a RecordArray. This can be used to load additional links when present in the response JSON-API document.
store.query('post', { isRecent: true }).then((posts) => {
posts.get('links.next');
});
Thanks to @danmcclain for implementing this feature.
For more details on changes in the 2.7 beta, please review the Ember Data 2.7.0-beta.1 CHANGELOG.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。