Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass store to inverseFor in removeEmbeddedForeignKey #3270

Merged
merged 1 commit into from
Jun 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
});
});