Skip to content

Commit

Permalink
Merge pull request #4271 from pangratz/fix-references-value
Browse files Browse the repository at this point in the history
[BUGFIX beta] Ensure `null` is returned for Reference#value()
  • Loading branch information
bmac committed Mar 28, 2016
2 parents 4edd88a + 88a80da commit 4eb34ee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion addon/-private/system/references/belongs-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ BelongsToReference.prototype.push = function(objectOrPromise) {

BelongsToReference.prototype.value = function() {
var inverseRecord = this.belongsToRelationship.inverseRecord;
return inverseRecord && inverseRecord.record;

if (inverseRecord && inverseRecord.record) {
return inverseRecord.record;
}

return null;
};

BelongsToReference.prototype.load = function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/references/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ if (isEnabled("ds-references")) {
});

var familyReference = person.belongsTo('family');
assert.equal(familyReference.value(), null);
assert.strictEqual(familyReference.value(), null);
});

test("value() returns the referenced record when loaded", function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/references/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ if (isEnabled("ds-references")) {
});

var personsReference = family.hasMany('persons');
assert.equal(personsReference.value(), null);
assert.strictEqual(personsReference.value(), null);
});

test("value() returns the referenced records when all records are loaded", function(assert) {
Expand Down

0 comments on commit 4eb34ee

Please sign in to comment.