Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / output / Ext.data.HasManyAssociation.js
1 Ext.data.JsonP.Ext_data_HasManyAssociation({
2   "tagname": "class",
3   "name": "Ext.data.HasManyAssociation",
4   "doc": "<p>Represents a one-to-many relationship between two models. Usually created indirectly via a model definition:</p>\n\n\n\n\n<pre><code>Ext.define('Product', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'id',      type: 'int'},\n        {name: 'user_id', type: 'int'},\n        {name: 'name',    type: 'string'}\n    ]\n});\n\nExt.define('User', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'id',   type: 'int'},\n        {name: 'name', type: 'string'}\n    ],\n    // we can use the hasMany shortcut on the model to create a hasMany association\n    hasMany: {model: 'Product', name: 'products'}\n});\n</pre>\n\n\n<p></code></p>\n\n<p>Above we created Product and User models, and linked them by saying that a User hasMany Products. This gives\nus a new function on every User instance, in this case the function is called 'products' because that is the name\nwe specified in the association configuration above.</p>\n\n\n\n\n<p>This new function returns a specialized <a href=\"#/api/Ext.data.Store\" rel=\"Ext.data.Store\" class=\"docClass\">Store</a> which is automatically filtered to load\nonly Products for the given model instance:</p>\n\n\n\n\n<pre><code>//first, we load up a User with id of 1\nvar user = Ext.ModelManager.create({id: 1, name: 'Ed'}, 'User');\n\n//the user.products function was created automatically by the association and returns a <a href=\"#/api/Ext.data.Store\" rel=\"Ext.data.Store\" class=\"docClass\">Store</a>\n//the created store is automatically scoped to the set of Products for the User with id of 1\nvar products = user.products();\n\n//we still have all of the usual Store functions, for example it's easy to add a Product for this User\nproducts.add({\n    name: 'Another Product'\n});\n\n//saves the changes to the store - this automatically sets the new Product's user_id to 1 before saving\nproducts.sync();\n</code></pre>\n\n\n\n\n<p>The new Store is only instantiated the first time you call products() to conserve memory and processing time,\nthough calling products() a second time returns the same store instance.</p>\n\n\n\n\n<p><u>Custom filtering</u></p>\n\n\n\n\n<p>The Store is automatically furnished with a filter - by default this filter tells the store to only return\nrecords where the associated model's foreign key matches the owner model's primary key. For example, if a User\nwith ID = 100 hasMany Products, the filter loads only Products with user_id == 100.</p>\n\n\n\n\n<p>Sometimes we want to filter by another field - for example in the case of a Twitter search application we may\nhave models for Search and Tweet:</p>\n\n\n\n\n<pre><code>Ext.define('Search', {\n    extend: 'Ext.data.Model',\n    fields: [\n        'id', 'query'\n    ],\n\n    hasMany: {\n        model: 'Tweet',\n        name : 'tweets',\n        filterProperty: 'query'\n    }\n});\n\nExt.define('Tweet', {\n    extend: 'Ext.data.Model',\n    fields: [\n        'id', 'text', 'from_user'\n    ]\n});\n\n//returns a Store filtered by the filterProperty\nvar store = new Search({query: 'Sencha Touch'}).tweets();\n</code></pre>\n\n\n\n\n<p>The tweets association above is filtered by the query property by setting the <a href=\"#/api/Ext.data.HasManyAssociation-cfg-filterProperty\" rel=\"Ext.data.HasManyAssociation-cfg-filterProperty\" class=\"docClass\">filterProperty</a>, and is\nequivalent to this:</p>\n\n\n\n\n<pre><code>var store = new Ext.data.Store({\n    model: 'Tweet',\n    filters: [\n        {\n            property: 'query',\n            value   : 'Sencha Touch'\n        }\n    ]\n});\n</code></pre>\n\n",
5   "extends": "Ext.data.Association",
6   "mixins": [
7
8   ],
9   "alternateClassNames": [
10
11   ],
12   "xtype": null,
13   "author": "Ed Spencer",
14   "docauthor": null,
15   "singleton": false,
16   "private": false,
17   "cfg": [
18     {
19       "tagname": "cfg",
20       "name": "associatedModel",
21       "member": "Ext.data.Association",
22       "type": "String",
23       "doc": "<p>The string name of the model that is being associated with. Required</p>\n",
24       "private": false,
25       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
26       "linenr": 124,
27       "html_filename": "Association.html",
28       "href": "Association.html#Ext-data-Association-cfg-associatedModel"
29     },
30     {
31       "tagname": "cfg",
32       "name": "associationKey",
33       "member": "Ext.data.Association",
34       "type": "String",
35       "doc": "<p>The name of the property in the data to read the association from.\nDefaults to the name of the associated model.</p>\n",
36       "private": false,
37       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
38       "linenr": 138,
39       "html_filename": "Association.html",
40       "href": "Association.html#Ext-data-Association-cfg-associationKey"
41     },
42     {
43       "tagname": "cfg",
44       "name": "autoLoad",
45       "member": "Ext.data.HasManyAssociation",
46       "type": "Boolean",
47       "doc": "<p>True to automatically load the related store from a remote source when instantiated.\nDefaults to <tt>false</tt>.</p>\n",
48       "private": false,
49       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
50       "linenr": 167,
51       "html_filename": "HasManyAssociation.html",
52       "href": "HasManyAssociation.html#Ext-data-HasManyAssociation-cfg-autoLoad"
53     },
54     {
55       "tagname": "cfg",
56       "name": "filterProperty",
57       "member": "Ext.data.HasManyAssociation",
58       "type": "String",
59       "doc": "<p>Optionally overrides the default filter that is set up on the associated Store. If\nthis is not set, a filter is automatically created which filters the association based on the configured\n<a href=\"#/api/Ext.data.HasManyAssociation-cfg-foreignKey\" rel=\"Ext.data.HasManyAssociation-cfg-foreignKey\" class=\"docClass\">foreignKey</a>. See intro docs for more details. Defaults to undefined</p>\n",
60       "private": false,
61       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
62       "linenr": 161,
63       "html_filename": "HasManyAssociation.html",
64       "href": "HasManyAssociation.html#Ext-data-HasManyAssociation-cfg-filterProperty",
65       "shortDoc": "Optionally overrides the default filter that is set up on the associated Store. If\nthis is not set, a filter is autom..."
66     },
67     {
68       "tagname": "cfg",
69       "name": "foreignKey",
70       "member": "Ext.data.HasManyAssociation",
71       "type": "String",
72       "doc": "<p>The name of the foreign key on the associated model that links it to the owner\nmodel. Defaults to the lowercased name of the owner model plus \"_id\", e.g. an association with a where a\nmodel called Group hasMany Users would create 'group_id' as the foreign key. When the remote store is loaded,\nthe store is automatically filtered so that only records with a matching foreign key are included in the\nresulting child store. This can be overridden by specifying the <a href=\"#/api/Ext.data.HasManyAssociation-cfg-filterProperty\" rel=\"Ext.data.HasManyAssociation-cfg-filterProperty\" class=\"docClass\">filterProperty</a>.</p>\n\n<pre><code>Ext.define('Group', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name'],\n    hasMany: 'User'\n});\n\nExt.define('User', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name', 'group_id'], // refers to the id of the group that this user belongs to\n    belongsTo: 'Group'\n});\n</code></pre>\n\n",
73       "private": false,
74       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
75       "linenr": 111,
76       "html_filename": "HasManyAssociation.html",
77       "href": "HasManyAssociation.html#Ext-data-HasManyAssociation-cfg-foreignKey",
78       "shortDoc": "The name of the foreign key on the associated model that links it to the owner\nmodel. Defaults to the lowercased name..."
79     },
80     {
81       "tagname": "cfg",
82       "name": "name",
83       "member": "Ext.data.HasManyAssociation",
84       "type": "String",
85       "doc": "<p>The name of the function to create on the owner model to retrieve the child store.\nIf not specified, the pluralized name of the child model is used.</p>\n\n<pre><code>// This will create a users() method on any Group model instance\nExt.define('Group', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name'],\n    hasMany: 'User'\n});\nvar group = new Group();\nconsole.log(group.users());\n\n// The method to retrieve the users will now be getUserList\nExt.define('Group', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name'],\n    hasMany: {model: 'User', name: 'getUserList'}\n});\nvar group = new Group();\nconsole.log(group.getUserList());\n</code></pre>\n\n",
86       "private": false,
87       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
88       "linenr": 132,
89       "html_filename": "HasManyAssociation.html",
90       "href": "HasManyAssociation.html#Ext-data-HasManyAssociation-cfg-name",
91       "shortDoc": "The name of the function to create on the owner model to retrieve the child store.\nIf not specified, the pluralized n..."
92     },
93     {
94       "tagname": "cfg",
95       "name": "ownerModel",
96       "member": "Ext.data.Association",
97       "type": "String",
98       "doc": "<p>The string name of the model that owns the association. Required</p>\n",
99       "private": false,
100       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
101       "linenr": 120,
102       "html_filename": "Association.html",
103       "href": "Association.html#Ext-data-Association-cfg-ownerModel"
104     },
105     {
106       "tagname": "cfg",
107       "name": "primaryKey",
108       "member": "Ext.data.Association",
109       "type": "String",
110       "doc": "<p>The name of the primary key on the associated model. Defaults to 'id'.\nIn general this will be the <a href=\"#/api/Ext.data.Model-cfg-idProperty\" rel=\"Ext.data.Model-cfg-idProperty\" class=\"docClass\">Ext.data.Model.idProperty</a> of the Model.</p>\n",
111       "private": false,
112       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
113       "linenr": 128,
114       "html_filename": "Association.html",
115       "href": "Association.html#Ext-data-Association-cfg-primaryKey",
116       "shortDoc": "The name of the primary key on the associated model. Defaults to 'id'.\nIn general this will be the Ext.data.Model.idP..."
117     },
118     {
119       "tagname": "cfg",
120       "name": "reader",
121       "member": "Ext.data.Association",
122       "type": "Ext.data.reader.Reader",
123       "doc": "<p>A special reader to read associated data</p>\n",
124       "private": false,
125       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
126       "linenr": 134,
127       "html_filename": "Association.html",
128       "href": "Association.html#Ext-data-Association-cfg-reader"
129     },
130     {
131       "tagname": "cfg",
132       "name": "storeConfig",
133       "member": "Ext.data.HasManyAssociation",
134       "type": "Object",
135       "doc": "<p>Optional configuration object that will be passed to the generated Store. Defaults to\nundefined.</p>\n",
136       "private": false,
137       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
138       "linenr": 156,
139       "html_filename": "HasManyAssociation.html",
140       "href": "HasManyAssociation.html#Ext-data-HasManyAssociation-cfg-storeConfig"
141     },
142     {
143       "tagname": "cfg",
144       "name": "type",
145       "member": "Ext.data.HasManyAssociation",
146       "type": "String",
147       "doc": "<p>The type configuration can be used when creating associations using a configuration object.\nUse 'hasMany' to create a HasManyAssocation</p>\n\n<pre><code>associations: [{\n    type: 'hasMany',\n    model: 'User'\n}]\n</code></pre>\n\n",
148       "private": false,
149       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
150       "linenr": 172,
151       "html_filename": "HasManyAssociation.html",
152       "href": "HasManyAssociation.html#Ext-data-HasManyAssociation-cfg-type",
153       "shortDoc": "The type configuration can be used when creating associations using a configuration object.\nUse 'hasMany' to create a..."
154     }
155   ],
156   "method": [
157     {
158       "tagname": "method",
159       "name": "HasManyAssociation",
160       "member": "Ext.data.Association",
161       "doc": "\n",
162       "params": [
163         {
164           "type": "Object",
165           "name": "config",
166           "doc": "<p>Optional config object</p>\n",
167           "optional": false
168         }
169       ],
170       "return": {
171         "type": "void",
172         "doc": "\n"
173       },
174       "private": false,
175       "static": false,
176       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
177       "linenr": 1,
178       "html_filename": "Association.html",
179       "href": "Association.html#Ext-data-Association-method-constructor",
180       "shortDoc": "\n"
181     },
182     {
183       "tagname": "method",
184       "name": "getReader",
185       "member": "Ext.data.Association",
186       "doc": "<p>Get a specialized reader for reading associated data</p>\n",
187       "params": [
188
189       ],
190       "return": {
191         "type": "Ext.data.reader.Reader",
192         "doc": "<p>The reader, null if not supplied</p>\n"
193       },
194       "private": false,
195       "static": false,
196       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
197       "linenr": 212,
198       "html_filename": "Association.html",
199       "href": "Association.html#Ext-data-Association-method-getReader",
200       "shortDoc": "<p>Get a specialized reader for reading associated data</p>\n"
201     }
202   ],
203   "property": [
204     {
205       "tagname": "property",
206       "name": "associatedName",
207       "member": "Ext.data.Association",
208       "type": "String",
209       "doc": "<p>The name of the model is on the other end of the association (e.g. if a User model hasMany Orders, this is 'Order')</p>\n",
210       "private": false,
211       "static": false,
212       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
213       "linenr": 200,
214       "html_filename": "Association.html",
215       "href": "Association.html#Ext-data-Association-property-associatedName"
216     },
217     {
218       "tagname": "property",
219       "name": "ownerName",
220       "member": "Ext.data.Association",
221       "type": "String",
222       "doc": "<p>The name of the model that 'owns' the association</p>\n",
223       "private": false,
224       "static": false,
225       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
226       "linenr": 194,
227       "html_filename": "Association.html",
228       "href": "Association.html#Ext-data-Association-property-ownerName"
229     }
230   ],
231   "event": [
232
233   ],
234   "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/HasManyAssociation.js",
235   "linenr": 1,
236   "html_filename": "HasManyAssociation.html",
237   "href": "HasManyAssociation.html#Ext-data-HasManyAssociation",
238   "cssVar": [
239
240   ],
241   "cssMixin": [
242
243   ],
244   "component": false,
245   "superclasses": [
246     "Ext.data.Association"
247   ],
248   "subclasses": [
249
250   ],
251   "mixedInto": [
252
253   ],
254   "allMixins": [
255
256   ]
257 });