Skip to content

Commit

Permalink
Merge pull request #3270 from wecc/save-embedded-fix
Browse files Browse the repository at this point in the history
Pass store to inverseFor in removeEmbeddedForeignKey
  • Loading branch information
igorT committed Jun 9, 2015
2 parents b4b35a1 + e01fb16 commit 19fa1d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ var EmbeddedRecordsMixin = Ember.Mixin.create({
if (relationship.kind === 'hasMany') {
return;
} else if (relationship.kind === 'belongsTo') {
var parentRecord = snapshot.type.inverseFor(relationship.key);
var parentRecord = snapshot.type.inverseFor(relationship.key, this.store);
if (parentRecord) {
var name = parentRecord.name;
var embeddedSerializer = this.store.serializerFor(embeddedSnapshot.modelName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1537,3 +1537,38 @@ test("serializing relationships with an embedded and without calls super when no
ok(calledSerializeBelongsTo);
ok(calledSerializeHasMany);
});

test("serializing belongsTo correctly removes embedded foreign key", function() {
SecretWeapon.reopen({
superVillain: null
});
EvilMinion.reopen({
secretWeapon: DS.belongsTo('secret-weapon'),
superVillain: null
});

run(function() {
secretWeapon = env.store.createRecord('secret-weapon', { name: "Secret Weapon" });
evilMinion = env.store.createRecord('evil-minion', { name: "Evil Minion", secretWeapon: secretWeapon });
});

env.registry.register('serializer:evil-minion', DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
secretWeapon: { embedded: 'always' }
}
}));

var serializer = env.container.lookup("serializer:evil-minion");
var json;

run(function() {
json = serializer.serialize(evilMinion._createSnapshot());
});

deepEqual(json, {
name: "Evil Minion",
secretWeapon: {
name: "Secret Weapon"
}
});
});

0 comments on commit 19fa1d0

Please sign in to comment.