5

I'd like to subclass a model that I've created using Sencha Architect. Say I have a model called BaseModel that I've already created, and I need to create another model, call it MyModel, which extends BaseModel. In code, it would look something like this:

// BaseModel.js
Ext.define('MyApp.model.BaseModel', {
   extend: 'Ext.data.Model',

   fields: [...]
});

and

// MyModel.js
Ext.define('MyApp.model.MyModel', {
   extend: 'MyApp.model.BaseModel',

   fields: [...]
});

I'm new to ExtJS and Sencha Architect but this is something that's so simple to do in code and so important to proper software design that I imagine there must be a way to do this in Architect. Unfortunately I couldn't figure out how to do this easily. After some digging I found this in the Sencha docs, http://docs.sencha.com/architect/2/#!/guide/classes, which states the following under the heading "Custom Classes":

While the features described here enable the creation of classes from the supported items in the Toolbox, sometimes you may need to create a plain parentless class or a class that extends another class that does not appear in the Toolbox. You can do this in Architect by using the Class item in the Toolbox.

Okay, sounds promising — so I tried that. In the project inspector I hit the plus sign, went to "Class", and within that hit "Model". So now I have a custom Model class in my project. I call it MyModel and I set the "extend" config to be MyApp.model.BaseModel. So now at least the code is correct and looks like what I have above. However, Architect seems to have no idea that the MyModel class is a model, even though it's sitting in the "Model" section of my Project Inspector and extends BaseModel. It doesn't have any of the Model config properties like "fields" that I need to specify, and I can't associate MyModel with any kind of Store. In other words, Architect treats MyModel as a completely custom class and doesn't expose any Model behavior. That basically makes this way of subclassing completely useless — I can subclass a Model but then I can't use it as a model anywhere in my project, so what's the point?

So the question is how do I get Architect to treat MyModel as an actual model? Is this not the correct way to subclass in Architect? I'm just starting my project but I foresee needing to subclass very often, whether it's models, controllers, stores, etc. and if I can't do this with Architect it's a severe limitation.

user2041338
  • 211
  • 3
  • 6

2 Answers2

0

You're doing all the right things. Architect in its current form 'works' this way but there is another which I think will provide better results.

Try using a traditional model and use createAlias with a userAlias set on the base model aka xtype

Phil Strong
  • 1,014
  • 9
  • 11
  • Do you mean to set userAlias on the base class or derived? How is then base/derived relationship established? – matejk Nov 29 '13 at 17:19
0

I experienced the same issue, which would have been a deal breaker in terms of using architect.

I was able to work around it by creating a custom class, extending the existing model, and then creating custom properties on the new class: "fields","hasMany","proxy" etc.

You can set the properties to type Array or Object which then lets you edit the fields in the code editor.

This isn't a perfect solution as architect does not recognise the class as a model, and hence you can't drag and drop fields etc.

However the outputted code is faithful to a natively created model.

Hope this helps, Ben

Ben Cook
  • 40
  • 4