Skip to content

Commit

Permalink
fix model when id property is shadowed by a method
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Sloan committed Sep 7, 2012
1 parent f23da29 commit b865588
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ steal('can/util','can/observe', function( can ) {
modelNum = 0,
ignoreHookup = /change.observe\d+/,
getId = function( inst ) {
return inst[inst.constructor.id];
return inst.__get(inst.constructor.id);
},
// Ajax `options` generator function
ajax = function( ajaxOb, data, type, dataType, success, error ) {
Expand Down
16 changes: 16 additions & 0 deletions model/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ module("can/model", {

var isDojo = (typeof dojo !== "undefined");

test("shadowed id", function(){
var MyModel = can.Model({
id: 'foo'
},{
foo: function() {
return this.attr('foo');
}
});

var newModel = new MyModel({});
ok(newModel.isNew(),'new model is isNew');
var oldModel = new MyModel({foo:'bar'});
ok(!oldModel.isNew(),'old model is not new');
equals(oldModel.foo(),'bar','method can coexist with attribute');
});

test("CRUD", function(){


Expand Down

0 comments on commit b865588

Please sign in to comment.