These are chat archives for canjs/canjs

Nov 2015
Jeroen Cornelissen
Nov 23 2015 13:11

How do you extend the instanceProperties of a can.Model
I need to have 2 myModels, because the model store gets repopulated.

var myModel = can.Model.extend({ 
}, {
    findAllItems : function(params) {
myModel.List = can.Model.List({}, {});
return myModel;

I want a clone/duplicate of myModel. I tried it like this, but then I lose the findAllItems function on a model instance.

myModel.findAll(); ...

var otherModel = myModel.extend();
otherModel.findAll(); ...
Nov 23 2015 20:14
@jeroencornelissen You might be confused. myModel and otherModel are both constructor functions so neither will have the findAllItems prototype method. For that, you would need an instance. You probably want to place findAllItems on the constructor of myModel which will allow it to be called with otherModel.findAllitems.
The built-in functions like findAll and findOne are generated during extend() rather than inherited so you'll probably have to just copy them over.
Nov 23 2015 20:26
The model store issue might be tricky though. You'd have to override makeFindAll to return models of the parent constructor and possibly more. You could try using can-connect and use the same connection/store for the parent and child constructs. I'm not using it yet, but can-connect is supposed to provide a lot more flexibility over the model layer (and is the future).