active-model-adapter
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -145,5 +145,7 @@ import Ember from 'ember'; | ||
@method ajaxError | ||
@param {Object} jqXHR | ||
@return error | ||
@method handleResponse | ||
@param {Number} status | ||
@param {Object} headers | ||
@param {Object} payload | ||
@return {Object | DS.AdapterError} response | ||
*/ | ||
@@ -150,0 +152,0 @@ handleResponse: function(status, headers, payload) { |
@@ -12,2 +12,3 @@ import DS from 'ember-data'; | ||
decamelize, | ||
pluralize, | ||
camelize, | ||
@@ -252,2 +253,13 @@ underscore | ||
/** | ||
* @private | ||
*/ | ||
_keyForIDLessRelationship: function(key, relationshipType, type) { | ||
if (relationshipType === 'hasMany') { | ||
return underscore(pluralize(key)); | ||
} else { | ||
return underscore(singularize(key)); | ||
} | ||
}, | ||
extractRelationships: function(modelClass, resourceHash) { | ||
@@ -257,2 +269,9 @@ modelClass.eachRelationship(function (key, relationshipMeta) { | ||
var idLessKey = this._keyForIDLessRelationship(key, relationshipMeta.kind, "deserialize"); | ||
// converts post to post_id, posts to post_ids | ||
if (resourceHash[idLessKey] && typeof relationshipMeta[relationshipKey] === 'undefined') { | ||
resourceHash[relationshipKey] = resourceHash[idLessKey]; | ||
} | ||
// prefer the format the AMS gem expects, e.g.: | ||
@@ -259,0 +278,0 @@ // relationship: {id: id, type: type} |
@@ -6,7 +6,13 @@ import ActiveModelAdapter from "active-model-adapter"; | ||
name: 'active-model-adapter', | ||
initialize: function() { | ||
var application = arguments[1] || arguments[0]; | ||
application.register('adapter:-active-model', ActiveModelAdapter); | ||
application.register('serializer:-active-model', ActiveModelSerializer); | ||
initialize: function(app) { | ||
if (arguments.length === 1) { | ||
// support the old registration API | ||
app.register('adapter:-active-model', ActiveModelAdapter); | ||
app.register('serializer:-active-model', ActiveModelSerializer); | ||
} else { | ||
let registry = app; | ||
registry.register('adapter:-active-model', ActiveModelAdapter); | ||
registry.register('serializer:-active-model', ActiveModelSerializer); | ||
} | ||
} | ||
}; |
# Ember Data ActiveModel Adapter Changelog | ||
## Master | ||
## 2.1.0 | ||
- [#80](https://github.com/ember-data/active-model-adapter/pull/80) [bugfix] Allow relationships to not have the _id suffix | ||
- [#51](https://github.com/ember-data/active-model-adapter/pull/51) [bugfix] add tests around errors | ||
@@ -5,0 +9,0 @@ - [#52](https://github.com/ember-data/active-model-adapter/pull/52) fix issue where attributes are getting erased when using when using the DS.EmbeddedRecordsMixin with a polymorphic embedded model |
@@ -0,1 +1,2 @@ | ||
/*jshint node:true*/ | ||
module.exports = { | ||
@@ -2,0 +3,0 @@ scenarios: [ |
@@ -0,1 +1,2 @@ | ||
/*jshint node:true*/ | ||
'use strict'; | ||
@@ -2,0 +3,0 @@ |
{ | ||
"name": "active-model-adapter", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"repository": "https://github.com/ember-data/active-model-adapter", | ||
@@ -21,26 +21,31 @@ "description": "The default blueprint for ember-cli addons.", | ||
"devDependencies": { | ||
"broccoli-asset-rev": "^2.0.2", | ||
"broccoli-babel-transpiler": "^5.1.1", | ||
"broccoli-asset-rev": "^2.4.1", | ||
"broccoli-babel-transpiler": "^5.5.0", | ||
"broccoli-concat": "0.0.13", | ||
"broccoli-es3-safe-recast": "^2.0.0", | ||
"broccoli-funnel": "^0.2.3", | ||
"broccoli-merge-trees": "^0.2.1", | ||
"broccoli-replace": "^0.3.1", | ||
"broccoli-stew": "^0.3.2", | ||
"ember-cli": "^1.13.0", | ||
"ember-cli-app-version": "0.3.3", | ||
"broccoli-funnel": "^1.0.1", | ||
"broccoli-merge-trees": "^1.1.0", | ||
"broccoli-replace": "^0.11.0", | ||
"broccoli-stew": "^1.0.4", | ||
"ember-cli": "^2.2.0-beta.1", | ||
"ember-cli-app-version": "^1.0.0", | ||
"ember-cli-content-security-policy": "0.4.0", | ||
"ember-cli-dependency-checker": "^1.0.0", | ||
"ember-cli-htmlbars": "0.7.6", | ||
"ember-cli-inject-live-reload": "^1.3.0", | ||
"ember-cli-pretender": "0.4.0", | ||
"ember-cli-qunit": "0.3.13", | ||
"ember-cli-uglify": "^1.0.1", | ||
"ember-data": "^2.0.0", | ||
"ember-disable-prototype-extensions": "^1.0.0", | ||
"ember-disable-proxy-controllers": "^1.0.0", | ||
"ember-export-application-global": "^1.0.2", | ||
"ember-try": "0.0.7", | ||
"ember-watson": "^0.5.7", | ||
"ember-cli-dependency-checker": "^1.2.0", | ||
"ember-cli-htmlbars": "^1.0.1", | ||
"ember-cli-htmlbars-inline-precompile": "^0.3.1", | ||
"ember-cli-inject-live-reload": "^1.4.0", | ||
"ember-cli-pretender": "0.5.0", | ||
"ember-cli-qunit": "^1.1.0", | ||
"ember-cli-release": "0.2.8", | ||
"ember-cli-sri": "^1.2.0", | ||
"ember-cli-uglify": "^1.2.0", | ||
"ember-data": "^2.2.1", | ||
"ember-disable-prototype-extensions": "^1.0.1", | ||
"ember-disable-proxy-controllers": "^1.0.1", | ||
"ember-export-application-global": "^1.0.5", | ||
"ember-resolver": "^2.0.3", | ||
"ember-try": "~0.0.8", | ||
"ember-watson": "^0.7.0", | ||
"github": "^0.2.4", | ||
"loader.js": "4.0.1", | ||
"rsvp": "^3.1.0" | ||
@@ -52,3 +57,3 @@ }, | ||
"dependencies": { | ||
"ember-cli-babel": "^5.0.0" | ||
"ember-cli-babel": "^5.1.6" | ||
}, | ||
@@ -55,0 +60,0 @@ "ember-addon": { |
108
README.md
@@ -17,3 +17,3 @@ # Ember Data ActiveModel Adapter [![Build Status](https://travis-ci.org/ember-data/active-model-adapter.svg?branch=master)](https://travis-ci.org/ember-data/active-model-adapter) | ||
```ruby | ||
gem 'active-model-adapter-source', '~>1.13' # or whatever version you need | ||
gem 'active-model-adapter-source', '~>2.0' # or whatever version you need | ||
``` | ||
@@ -69,2 +69,5 @@ | ||
Since ActiveModelAdapter 2.1.0 however, you don't need the "_id" or | ||
"_ids" suffix on keys for relationships. | ||
### Conventional Names | ||
@@ -137,2 +140,105 @@ | ||
### Polymorphic Relationships | ||
If your model has polymorphic relationships, the ActiveModelAdapter | ||
supports two forms in your response. | ||
When using ActiveModelSerializers in Rails, you can opt into this | ||
payload using the `polymorphic: true` option when calling `has_many` or | ||
`belongs_to`. | ||
```ruby | ||
class BookSerializer | ||
attributes :id, :name | ||
belongs_to :person, polymorphic: true | ||
end | ||
``` | ||
The first, and preferred format, is to use the name of the relationship | ||
as the key and an object with the type and foreign key as the value. | ||
For example, given the following model definitions: | ||
```javascript | ||
// app/models/book.js | ||
export default var Book = DS.Model.extend({ | ||
name: DS.attr(), | ||
author: DS.belongsTo('person', {polymorphic: true}) | ||
}); | ||
// app/models/author.js | ||
export default var Person = DS.Model.extend({ | ||
name: DS.attr(), | ||
books: DS.hasMany('book') | ||
}); | ||
``` | ||
The object would look like: | ||
```json | ||
{ | ||
"type": "person", | ||
"id": 1 | ||
} | ||
``` | ||
and the full payload would look like this: | ||
```javascript | ||
{ | ||
"book": { | ||
"id": "1", | ||
"name": "Yes, Please", | ||
"author": { // these are the lines | ||
"id": 1, // that define the | ||
"type": "person" // polymorphic relationship | ||
} | ||
}, | ||
"people": [{ | ||
"id": 1, | ||
"name": "Amy Poehler" | ||
}] | ||
} | ||
``` | ||
The second format allows you to specify using two keys in the model's | ||
payload following the format of `relationship_name_id` and | ||
`relationship_name_type`. **This format does not work with hasMany | ||
relationships.** This format **may also be removed for Ember Data 3.0**; | ||
it is currently only supported for legacy reasons. | ||
Using the above model definitions, the single model response would look | ||
like this: | ||
```javascript | ||
{ | ||
"book": { | ||
"id": "1", | ||
"name": "Yes, Please", | ||
"author_id": 1, // these two lines | ||
"author_type": "person" // tell Ember Data what the polymorphic | ||
// relationship is. | ||
} | ||
} | ||
``` | ||
The full response would be look like this: | ||
```javascript | ||
{ | ||
"book": { | ||
"id": "1", | ||
"name": "Yes, Please", | ||
"author_id": 1, // these two lines | ||
"author_type": "person" // tell Ember Data what the polymorphic | ||
// relationship is. | ||
}, | ||
"people": [{ | ||
"id": 1, | ||
"name": "Amy Poehler" | ||
}] | ||
} | ||
``` | ||
## Development Installation | ||
@@ -139,0 +245,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
40145
28
554
257
0
30
2
Updatedember-cli-babel@^5.1.6