1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-ModelManager'>/**
2 </span> * @author Ed Spencer
3 * @class Ext.ModelManager
4 * @extends Ext.AbstractManager
6 The ModelManager keeps track of all {@link Ext.data.Model} types defined in your application.
8 __Creating Model Instances__
9 Model instances can be created by using the {@link #create} function. It is also possible to do
10 this by using the Model type directly. The following snippets are equivalent:
13 extend: 'Ext.data.Model',
14 fields: ['first', 'last']
17 // method 1, create through the manager
18 Ext.ModelManager.create({
23 // method 2, create on the type directly
29 __Accessing Model Types__
30 A reference to a Model type can be obtained by using the {@link #getModel} function. Since models types
31 are normal classes, you can access the type directly. The following snippets are equivalent:
34 extend: 'Ext.data.Model',
35 fields: ['first', 'last']
38 // method 1, access model type through the manager
39 var UserType = Ext.ModelManager.getModel('User');
41 // method 2, reference the type directly
47 Ext.define('Ext.ModelManager', {
48 extend: 'Ext.AbstractManager',
49 alternateClassName: 'Ext.ModelMgr',
50 requires: ['Ext.data.Association'],
56 <span id='Ext-ModelManager-property-associationStack'> /**
57 </span> * Private stack of associations that must be created once their associated model has been defined
58 * @property associationStack
63 <span id='Ext-ModelManager-method-registerType'> /**
64 </span> * Registers a model definition. All model plugins marked with isDefault: true are bootstrapped
65 * immediately, as are any addition plugins defined in the model config.
68 registerType: function(name, config) {
69 var proto = config.prototype,
71 if (proto && proto.isModel) {
72 // registering an already defined model
75 // passing in a configuration
77 config.extend = 'Ext.data.Model';
79 model = Ext.define(name, config);
81 this.types[name] = model;
85 <span id='Ext-ModelManager-method-onModelDefined'> /**
87 * Private callback called whenever a model has just been defined. This sets up any associations
88 * that were waiting for the given model to be defined
89 * @param {Function} model The model that was just created
91 onModelDefined: function(model) {
92 var stack = this.associationStack,
93 length = stack.length,
95 association, i, created;
97 for (i = 0; i < length; i++) {
98 association = stack[i];
100 if (association.associatedModel == model.modelName) {
101 create.push(association);
105 for (i = 0, length = create.length; i < length; i++) {
107 this.types[created.ownerModel].prototype.associations.add(Ext.data.Association.create(created));
108 Ext.Array.remove(stack, created);
112 <span id='Ext-ModelManager-method-registerDeferredAssociation'> /**
113 </span> * Registers an association where one of the models defined doesn't exist yet.
114 * The ModelManager will check when new models are registered if it can link them
117 * @param {Ext.data.Association} association The association
119 registerDeferredAssociation: function(association){
120 this.associationStack.push(association);
123 <span id='Ext-ModelManager-method-getModel'> /**
124 </span> * Returns the {@link Ext.data.Model} for a given model name
125 * @param {String/Object} id The id of the model or the model instance.
127 getModel: function(id) {
129 if (typeof model == 'string') {
130 model = this.types[model];
135 <span id='Ext-ModelManager-method-create'> /**
136 </span> * Creates a new instance of a Model using the given data.
137 * @param {Object} data Data to initialize the Model's fields with
138 * @param {String} name The name of the model to create
139 * @param {Number} id Optional unique id of the Model instance (see {@link Ext.data.Model})
141 create: function(config, name, id) {
142 var con = typeof name == 'function' ? name : this.types[name || config.name];
144 return new con(config, id);
148 <span id='Ext-method-regModel'> /**
149 </span> * Creates a new Model class from the specified config object. See {@link Ext.data.Model} for full examples.
151 * @param {Object} config A configuration object for the Model you wish to create.
152 * @return {Ext.data.Model} The newly registered Model
156 Ext.regModel = function() {
158 if (Ext.isDefined(Ext.global.console)) {
159 Ext.global.console.warn('Ext.regModel has been deprecated. Models can now be created by extending Ext.data.Model: Ext.define("MyModel", {extend: "Ext.data.Model", fields: []});.');
162 return this.ModelManager.registerType.apply(this.ModelManager, arguments);
165 </pre></pre></body></html>