Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / output / Ext.data.BelongsToAssociation.js
1 Ext.data.JsonP.Ext_data_BelongsToAssociation({
2   "allMixins": [
3
4   ],
5   "deprecated": null,
6   "docauthor": null,
7   "members": {
8     "cfg": [
9       {
10         "type": "String",
11         "deprecated": null,
12         "alias": null,
13         "protected": false,
14         "tagname": "cfg",
15         "href": "Association.html#Ext-data-Association-cfg-associatedModel",
16         "shortDoc": "The string name of the model that is being associated with. ...",
17         "static": false,
18         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
19         "private": false,
20         "name": "associatedModel",
21         "owner": "Ext.data.Association",
22         "doc": "<p>The string name of the model that is being associated with. Required</p>\n",
23         "linenr": 122,
24         "html_filename": "Association.html"
25       },
26       {
27         "type": "String",
28         "deprecated": null,
29         "alias": null,
30         "protected": false,
31         "tagname": "cfg",
32         "href": "Association.html#Ext-data-Association-cfg-associationKey",
33         "shortDoc": "The name of the property in the data to read the association from. ...",
34         "static": false,
35         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
36         "private": false,
37         "name": "associationKey",
38         "owner": "Ext.data.Association",
39         "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",
40         "linenr": 136,
41         "html_filename": "Association.html"
42       },
43       {
44         "type": "String",
45         "deprecated": null,
46         "alias": null,
47         "protected": false,
48         "tagname": "cfg",
49         "href": "BelongsToAssociation.html#Ext-data-BelongsToAssociation-cfg-foreignKey",
50         "shortDoc": "The name of the foreign key on the owner model that links it to the associated\nmodel. ...",
51         "static": false,
52         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/BelongsToAssociation.js",
53         "private": false,
54         "name": "foreignKey",
55         "owner": "Ext.data.BelongsToAssociation",
56         "doc": "<p>The name of the foreign key on the owner model that links it to the associated\nmodel. Defaults to the lowercased name of the associated model plus \"_id\", e.g. an association with a\nmodel called Product would set up a product_id foreign key.</p>\n\n<pre><code>Ext.define('Order', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'date'],\n    hasMany: 'Product'\n});\n\nExt.define('Product', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name', 'order_id'], // refers to the id of the order that this product belongs to\n    belongsTo: 'Group'\n});\nvar product = new Product({\n    id: 1,\n    name: 'Product 1',\n    order_id: 22\n}, 1);\nproduct.getOrder(); // Will make a call to the server asking for order_id 22\n\n</code></pre>\n\n",
57         "linenr": 123,
58         "html_filename": "BelongsToAssociation.html"
59       },
60       {
61         "type": "String",
62         "deprecated": null,
63         "alias": null,
64         "protected": false,
65         "tagname": "cfg",
66         "href": "BelongsToAssociation.html#Ext-data-BelongsToAssociation-cfg-getterName",
67         "shortDoc": "The name of the getter function that will be added to the local model's prototype. ...",
68         "static": false,
69         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/BelongsToAssociation.js",
70         "private": false,
71         "name": "getterName",
72         "owner": "Ext.data.BelongsToAssociation",
73         "doc": "<p>The name of the getter function that will be added to the local model's prototype.\nDefaults to 'get' + the name of the foreign model, e.g. getCategory</p>\n",
74         "linenr": 149,
75         "html_filename": "BelongsToAssociation.html"
76       },
77       {
78         "type": "String",
79         "deprecated": null,
80         "alias": null,
81         "protected": false,
82         "tagname": "cfg",
83         "href": "Association.html#Ext-data-Association-cfg-ownerModel",
84         "shortDoc": "The string name of the model that owns the association. ...",
85         "static": false,
86         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
87         "private": false,
88         "name": "ownerModel",
89         "owner": "Ext.data.Association",
90         "doc": "<p>The string name of the model that owns the association. Required</p>\n",
91         "linenr": 118,
92         "html_filename": "Association.html"
93       },
94       {
95         "type": "String",
96         "deprecated": null,
97         "alias": null,
98         "protected": false,
99         "tagname": "cfg",
100         "href": "Association.html#Ext-data-Association-cfg-primaryKey",
101         "shortDoc": "The name of the primary key on the associated model. ...",
102         "static": false,
103         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
104         "private": false,
105         "name": "primaryKey",
106         "owner": "Ext.data.Association",
107         "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",
108         "linenr": 126,
109         "html_filename": "Association.html"
110       },
111       {
112         "type": "Ext.data.reader.Reader",
113         "deprecated": null,
114         "alias": null,
115         "protected": false,
116         "tagname": "cfg",
117         "href": "Association.html#Ext-data-Association-cfg-reader",
118         "static": false,
119         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
120         "private": false,
121         "name": "reader",
122         "owner": "Ext.data.Association",
123         "doc": "<p>A special reader to read associated data</p>\n",
124         "linenr": 132,
125         "html_filename": "Association.html"
126       },
127       {
128         "type": "String",
129         "deprecated": null,
130         "alias": null,
131         "protected": false,
132         "tagname": "cfg",
133         "href": "BelongsToAssociation.html#Ext-data-BelongsToAssociation-cfg-setterName",
134         "shortDoc": "The name of the setter function that will be added to the local model's prototype. ...",
135         "static": false,
136         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/BelongsToAssociation.js",
137         "private": false,
138         "name": "setterName",
139         "owner": "Ext.data.BelongsToAssociation",
140         "doc": "<p>The name of the setter function that will be added to the local model's prototype.\nDefaults to 'set' + the name of the foreign model, e.g. setCategory</p>\n",
141         "linenr": 154,
142         "html_filename": "BelongsToAssociation.html"
143       },
144       {
145         "type": "String",
146         "deprecated": null,
147         "alias": null,
148         "protected": false,
149         "tagname": "cfg",
150         "href": "BelongsToAssociation.html#Ext-data-BelongsToAssociation-cfg-type",
151         "shortDoc": "The type configuration can be used when creating associations using a configuration object. ...",
152         "static": false,
153         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/BelongsToAssociation.js",
154         "private": false,
155         "name": "type",
156         "owner": "Ext.data.BelongsToAssociation",
157         "doc": "<p>The type configuration can be used when creating associations using a configuration object.\nUse 'belongsTo' to create a HasManyAssocation</p>\n\n<pre><code>associations: [{\n    type: 'belongsTo',\n    model: 'User'\n}]\n</code></pre>\n\n",
158         "linenr": 159,
159         "html_filename": "BelongsToAssociation.html"
160       }
161     ],
162     "method": [
163       {
164         "deprecated": null,
165         "alias": null,
166         "href": "Association.html#Ext-data-Association-method-constructor",
167         "tagname": "method",
168         "protected": false,
169         "shortDoc": "Creates the Association object. ...",
170         "static": false,
171         "params": [
172           {
173             "type": "Object",
174             "optional": true,
175             "doc": "<p>(optional) Config object.</p>\n",
176             "name": "config"
177           }
178         ],
179         "private": false,
180         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
181         "doc": "<p>Creates the Association object.</p>\n",
182         "owner": "Ext.data.Association",
183         "name": "BelongsToAssociation",
184         "html_filename": "Association.html",
185         "return": {
186           "type": "Object",
187           "doc": "\n"
188         },
189         "linenr": 170
190       },
191       {
192         "deprecated": null,
193         "alias": null,
194         "protected": false,
195         "tagname": "method",
196         "href": "Association.html#Ext-data-Association-method-getReader",
197         "shortDoc": "Get a specialized reader for reading associated data ...",
198         "static": false,
199         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
200         "private": false,
201         "params": [
202
203         ],
204         "name": "getReader",
205         "owner": "Ext.data.Association",
206         "doc": "<p>Get a specialized reader for reading associated data</p>\n",
207         "linenr": 214,
208         "return": {
209           "type": "Ext.data.reader.Reader",
210           "doc": "<p>The reader, null if not supplied</p>\n"
211         },
212         "html_filename": "Association.html"
213       }
214     ],
215     "property": [
216       {
217         "type": "String",
218         "deprecated": null,
219         "alias": null,
220         "protected": false,
221         "tagname": "property",
222         "href": "Association.html#Ext-data-Association-property-associatedName",
223         "shortDoc": "The name of the model is on the other end of the association (e.g. ...",
224         "static": false,
225         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
226         "private": false,
227         "name": "associatedName",
228         "owner": "Ext.data.Association",
229         "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",
230         "linenr": 202,
231         "html_filename": "Association.html"
232       },
233       {
234         "type": "String",
235         "deprecated": null,
236         "alias": null,
237         "protected": false,
238         "tagname": "property",
239         "href": "Association.html#Ext-data-Association-property-ownerName",
240         "static": false,
241         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
242         "private": false,
243         "name": "ownerName",
244         "owner": "Ext.data.Association",
245         "doc": "<p>The name of the model that 'owns' the association</p>\n",
246         "linenr": 196,
247         "html_filename": "Association.html"
248       }
249     ],
250     "cssVar": [
251
252     ],
253     "cssMixin": [
254
255     ],
256     "event": [
257
258     ]
259   },
260   "singleton": false,
261   "alias": null,
262   "superclasses": [
263     "Ext.data.Association"
264   ],
265   "protected": false,
266   "tagname": "class",
267   "mixins": [
268
269   ],
270   "href": "BelongsToAssociation.html#Ext-data-BelongsToAssociation",
271   "subclasses": [
272
273   ],
274   "static": false,
275   "author": "Ed Spencer",
276   "component": false,
277   "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/BelongsToAssociation.js",
278   "private": false,
279   "alternateClassNames": [
280
281   ],
282   "name": "Ext.data.BelongsToAssociation",
283   "doc": "<p>Represents a many to one association with another model. The owner model is expected to have\na foreign key which references the primary key of the associated model:</p>\n\n\n\n\n<pre><code>Ext.define('Category', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'id',   type: 'int'},\n        {name: 'name', type: 'string'}\n    ]\n});\n\nExt.define('Product', {\n    extend: 'Ext.data.Model',\n    fields: [\n        {name: 'id',          type: 'int'},\n        {name: 'category_id', type: 'int'},\n        {name: 'name',        type: 'string'}\n    ],\n    // we can use the belongsTo shortcut on the model to create a belongsTo association\n    belongsTo: {type: 'belongsTo', model: 'Category'}\n});\n</code></pre>\n\n\n<p>In the example above we have created models for Products and Categories, and linked them together\nby saying that each Product belongs to a Category. This automatically links each Product to a Category\nbased on the Product's category_id, and provides new functions on the Product model:</p>\n\n\n\n\n<p><u>Generated getter function</u></p>\n\n\n\n\n<p>The first function that is added to the owner model is a getter function:</p>\n\n\n\n\n<pre><code>var product = new Product({\n    id: 100,\n    category_id: 20,\n    name: 'Sneakers'\n});\n\nproduct.getCategory(function(category, operation) {\n    //do something with the category object\n    alert(category.get('id')); //alerts 20\n}, this);\n</code></pre>\n\n\n\n\n<p>The getCategory function was created on the Product model when we defined the association. This uses the\nCategory's configured <a href=\"#/api/Ext.data.proxy.Proxy\" rel=\"Ext.data.proxy.Proxy\" class=\"docClass\">proxy</a> to load the Category asynchronously, calling the provided\ncallback when it has loaded.</p>\n\n\n\n\n<p>The new getCategory function will also accept an object containing success, failure and callback properties\n- callback will always be called, success will only be called if the associated model was loaded successfully\nand failure will only be called if the associatied model could not be loaded:</p>\n\n\n\n\n<pre><code>product.getCategory({\n    callback: function(category, operation) {}, //a function that will always be called\n    success : function(category, operation) {}, //a function that will only be called if the load succeeded\n    failure : function(category, operation) {}, //a function that will only be called if the load did not succeed\n    scope   : this //optionally pass in a scope object to execute the callbacks in\n});\n</code></pre>\n\n\n\n\n<p>In each case above the callbacks are called with two arguments - the associated model instance and the\n<a href=\"#/api/Ext.data.Operation\" rel=\"Ext.data.Operation\" class=\"docClass\">operation</a> object that was executed to load that instance. The Operation object is\nuseful when the instance could not be loaded.</p>\n\n\n\n\n<p><u>Generated setter function</u></p>\n\n\n\n\n<p>The second generated function sets the associated model instance - if only a single argument is passed to\nthe setter then the following two calls are identical:</p>\n\n\n\n\n<pre><code>//this call\nproduct.setCategory(10);\n\n//is equivalent to this call:\nproduct.set('category_id', 10);\n</code></pre>\n\n\n<p>If we pass in a second argument, the model will be automatically saved and the second argument passed to\nthe owner model's <a href=\"#/api/Ext.data.Model-method-save\" rel=\"Ext.data.Model-method-save\" class=\"docClass\">save</a> method:</p>\n\n\n<pre><code>product.setCategory(10, function(product, operation) {\n    //the product has been saved\n    alert(product.get('category_id')); //now alerts 10\n});\n\n//alternative syntax:\nproduct.setCategory(10, {\n    callback: function(product, operation), //a function that will always be called\n    success : function(product, operation), //a function that will only be called if the load succeeded\n    failure : function(product, operation), //a function that will only be called if the load did not succeed\n    scope   : this //optionally pass in a scope object to execute the callbacks in\n})\n</code></pre>\n\n\n\n\n<p><u>Customisation</u></p>\n\n\n\n\n<p>Associations reflect on the models they are linking to automatically set up properties such as the\n<a href=\"#/api/Ext.data.BelongsToAssociation-cfg-primaryKey\" rel=\"Ext.data.BelongsToAssociation-cfg-primaryKey\" class=\"docClass\">primaryKey</a> and <a href=\"#/api/Ext.data.BelongsToAssociation-cfg-foreignKey\" rel=\"Ext.data.BelongsToAssociation-cfg-foreignKey\" class=\"docClass\">foreignKey</a>. These can alternatively be specified:</p>\n\n\n\n\n<pre><code>Ext.define('Product', {\n    fields: [...],\n\n    associations: [\n        {type: 'belongsTo', model: 'Category', primaryKey: 'unique_id', foreignKey: 'cat_id'}\n    ]\n});\n </code></pre>\n\n\n\n\n<p>Here we replaced the default primary key (defaults to 'id') and foreign key (calculated as 'category_id')\nwith our own settings. Usually this will not be needed.</p>\n\n",
284   "mixedInto": [
285
286   ],
287   "linenr": 1,
288   "xtypes": [
289
290   ],
291   "html_filename": "BelongsToAssociation.html",
292   "extends": "Ext.data.Association"
293 });