Skip to content

Commit

Permalink
Don't force relationship links to be strings
Browse files Browse the repository at this point in the history
  • Loading branch information
wecc committed Apr 22, 2015
1 parent d84dabe commit 455b3d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Relationship.prototype = {

updateLink: function(link) {
Ember.warn("You have pushed a record of type '" + this.record.constructor.typeKey + "' with '" + this.key + "' as a link, but the association is not an async relationship.", this.isAsync);
Ember.assert("You have pushed a record of type '" + this.record.constructor.typeKey + "' with '" + this.key + "' as a link, but the value of that link is not a string.", typeof link === 'string' || link === null);
if (link !== this.link) {
this.link = link;
this.linkPromise = null;
Expand Down
25 changes: 14 additions & 11 deletions packages/ember-data/tests/unit/store/push-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,23 +486,26 @@ test('Calling push with a link for a non async relationship should warn', functi
}, /You have pushed a record of type 'person' with 'phoneNumbers' as a link, but the association is not an async relationship./);
});

test('Calling push with a link containing an object throws an assertion error', function() {
test('Calling push with a link containing an object', function() {
Person.reopen({
phoneNumbers: hasMany('phone-number', { async: true })
});

expectAssertion(function() {
run(function() {
store.push('person', {
id: '1',
links: {
phoneNumbers: {
href: '/api/people/1/phone-numbers'
}
run(function() {
store.push('person', {
id: '1',
firstName: 'Tan',
links: {
phoneNumbers: {
href: '/api/people/1/phone-numbers'
}
});
}
});
}, "You have pushed a record of type 'person' with 'phoneNumbers' as a link, but the value of that link is not a string.");
});

var person = store.getById('person', 1);

equal(person.get('firstName'), "Tan", "you can use links that contain an object as a value");
});

test('Calling push with a link containing the value null', function() {
Expand Down

0 comments on commit 455b3d3

Please sign in to comment.