Skip to content

Commit

Permalink
Use Ember.none() in belongsTo#hasAssociation to catch undefined value…
Browse files Browse the repository at this point in the history
…s as well as null
  • Loading branch information
Christopher Swasey committed May 25, 2012
1 parent 1ed90c1 commit 1c6247b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ember-data/lib/system/associations/belongs_to.js
Expand Up @@ -28,7 +28,7 @@ var hasAssociation = function(type, options, one) {

if (arguments.length === 2) {
key = options.key || get(this, 'namingConvention').foreignKey(key);
this.send('setAssociation', { key: key, value: value === null ? null : get(value, 'clientId') });
this.send('setAssociation', { key: key, value: Ember.none(value) ? null : get(value, 'clientId') });
//data.setAssociation(key, get(value, 'clientId'));
// put the client id in `key` in the data hash
return value;
Expand Down
19 changes: 19 additions & 0 deletions packages/ember-data/tests/unit/associations_test.js
Expand Up @@ -543,3 +543,22 @@ test("embedded associations should respect namingConvention", function() {
var person = store.find(Person, 1);
equal(getPath(person, 'myCustomTags.firstObject.name'), "UN-friendly", "hasMany tag should be set properly");
});

test("calling createRecord and passing in an undefined value for an association should be treated as if null", function () {
expect(1);

var Tag = DS.Model.extend({
name: DS.attr('string')
});

var Person = DS.Model.extend({
name: DS.attr('string'),
tag: DS.belongsTo(Tag, { embedded: true })
});

var store = DS.Store.create();

store.createRecord(Person, {tag: undefined});

ok(true);
});

0 comments on commit 1c6247b

Please sign in to comment.