Skip to content

Commit

Permalink
Merge pull request #4025 from GCorbel/master
Browse files Browse the repository at this point in the history
Use keyForReliationship for belongsTo and hasMany
  • Loading branch information
bmac committed Dec 31, 2015
2 parents 1332045 + 6951988 commit 99dec65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions addon/-private/serializers/embedded-records-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default Ember.Mixin.create({

_serializeEmbeddedBelongsTo(snapshot, json, relationship) {
let embeddedSnapshot = snapshot.belongsTo(relationship.key);
let serializedKey = this.keyForAttribute(relationship.key, 'serialize');
let serializedKey = this.keyForRelationship(relationship.key, 'serialize');
if (!embeddedSnapshot) {
json[serializedKey] = null;
} else {
Expand Down Expand Up @@ -332,7 +332,7 @@ export default Ember.Mixin.create({
},

_serializeEmbeddedHasMany(snapshot, json, relationship) {
let serializedKey = this.keyForAttribute(relationship.key, 'serialize');
let serializedKey = this.keyForRelationship(relationship.key, 'serialize');

warn(
`The embedded relationship '${serializedKey}' is undefined for '${snapshot.modelName}' with id '${snapshot.id}'. Please include it in your original payload.`,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/serializers/embedded-records-mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ test("serialize with embedded objects and a custom keyForAttribute (hasMany rela
});

env.registry.register('serializer:home-planet', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
keyForAttribute(key) {
keyForRelationship(key) {
return key + '-custom';
},
attrs: {
Expand All @@ -926,7 +926,7 @@ test("serialize with embedded objects and a custom keyForAttribute (hasMany rela
});

assert.deepEqual(json, {
"name-custom": "Villain League",
"name": "Villain League",
"villains-custom": [{
id: get(tom, "id"),
firstName: "Tom",
Expand Down

0 comments on commit 99dec65

Please sign in to comment.