diff --git a/model/list/list.js b/model/list/list.js index 14600930..b278ab27 100644 --- a/model/list/list.js +++ b/model/list/list.js @@ -1,4 +1,4 @@ -steal('can/model/list','jquerypp/model').then(function() { +steal('can/util', 'can/model/list','jquerypp/model', function(can) { // List.get used to take a model or list of models var getList = $.Model.List.prototype.get; $.Model.List.prototype.get = function(arg) { @@ -9,17 +9,21 @@ steal('can/model/list','jquerypp/model').then(function() { ids.push(this.attr('id')); }); arg = ids; + return getList.apply(this,arg); } else if(arg.attr && arg.constructor && (id = arg.attr(arg.constructor.id))) { arg = id; + return getList.apply(this,[arg]); + } else { + return getList.apply(this,arguments); } - return getList.apply(this,arguments); }; // restore the ability to push a list!arg var push = $.Model.List.prototype.push; $.Model.List.prototype.push = function(arg) { if(arg instanceof $.Model.List) { - arg = can.makeArray(arg); + return push.apply(this,can.makeArray(arg)); + } else { + return push.apply(this,arguments); } - return push.apply(this,arguments); }; }); diff --git a/model/list/list_test.js b/model/list/list_test.js index c66fba07..2ee82ace 100644 --- a/model/list/list_test.js +++ b/model/list/list_test.js @@ -42,6 +42,30 @@ test("create", function(){ equals(this.people.get("a2")[0].id,"a2" , "get works") }) +test("get", function(){ + var listOfPeople = new Person.List([ + new Person({ id: 1000, name: "Barry" }), + new Person({ id: 1001, name: "Colin" }) + ]); + var instanceMatch = listOfPeople.get(listOfPeople.attr('0')); + equals(instanceMatch[0].id, 1000, 'get works with model instance'); + equals(instanceMatch.length, 1, 'result is correct length'); + + var listMatch = listOfPeople.get(new Person.List([listOfPeople.attr('0')])); + equals(listMatch[0].id, 1000, 'get works with model list instance'); + equals(listMatch.length, 1, 'result is correct length'); +}) + +test("push another list", function(){ + var listOfPeople = new Person.List(); + listOfPeople.push( + new Person({ name: "Barry" }), + new Person({ name: "Colin" }) + ); + equals(this.people.length, 20, 'started with 20 people'); + this.people.push(listOfPeople); + equals(this.people.length, 22, 'pushed 2 more people'); +}) test("splice", function(){ ok(this.people.get("a1").length,"something where a1 is")