Skip to content

Commit

Permalink
Merge pull request #3183 from sly7-7/fix-for-3172
Browse files Browse the repository at this point in the history
fix belongs-to when set with a resolved promise
  • Loading branch information
igorT committed Jun 3, 2015
2 parents 91a3b85 + b615765 commit f40b1f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ BelongsToRelationship.prototype.addRecord = function(newRecord) {
BelongsToRelationship.prototype.setRecordPromise = function(newPromise) {
var content = newPromise.get && newPromise.get('content');
Ember.assert("You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call.", content !== undefined);
this.setRecord(content);
this.setRecord(content ? content._internalModel : content);
};

BelongsToRelationship.prototype._super$removeRecordFromOwn = Relationship.prototype.removeRecordFromOwn;
Expand Down Expand Up @@ -137,7 +137,7 @@ BelongsToRelationship.prototype.getRecord = function() {

return PromiseObject.create({
promise: promise,
content: this.inverseRecord
content: this.inverseRecord ? this.inverseRecord.getRecord() : null
});
} else {
if (this.inverseRecord === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,34 @@ test("A record with an async belongsTo relationship returning null should resolv
}));
});

test("A record can be created with a resolved belongsTo promise", function() {
expect(1);

var Group = DS.Model.extend({
people: DS.hasMany()
});

var Person = DS.Model.extend({
group: DS.belongsTo({ async: true })
});

env.registry.register('model:group', Group);
env.registry.register('model:person', Person);

var group;
run(function() {
group = store.push('group', { id: 1 });
});

var groupPromise = store.find('group', 1);
groupPromise.then(async(function(group) {
var person = env.store.createRecord('person', {
group: groupPromise
});
equal(person.get('group.content'), group);
}));
});

test("polymorphic belongsTo type-checks check the superclass when MODEL_FACTORY_INJECTIONS is enabled", function() {
expect(1);

Expand Down

0 comments on commit f40b1f9

Please sign in to comment.