Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / output / Ext.data.Association.js
1 Ext.data.JsonP.Ext_data_Association({
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": "Association.html#Ext-data-Association-cfg-ownerModel",
50         "shortDoc": "The string name of the model that owns the association. ...",
51         "static": false,
52         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
53         "private": false,
54         "name": "ownerModel",
55         "owner": "Ext.data.Association",
56         "doc": "<p>The string name of the model that owns the association. Required</p>\n",
57         "linenr": 118,
58         "html_filename": "Association.html"
59       },
60       {
61         "type": "String",
62         "deprecated": null,
63         "alias": null,
64         "protected": false,
65         "tagname": "cfg",
66         "href": "Association.html#Ext-data-Association-cfg-primaryKey",
67         "shortDoc": "The name of the primary key on the associated model. ...",
68         "static": false,
69         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
70         "private": false,
71         "name": "primaryKey",
72         "owner": "Ext.data.Association",
73         "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",
74         "linenr": 126,
75         "html_filename": "Association.html"
76       },
77       {
78         "type": "Ext.data.reader.Reader",
79         "deprecated": null,
80         "alias": null,
81         "protected": false,
82         "tagname": "cfg",
83         "href": "Association.html#Ext-data-Association-cfg-reader",
84         "static": false,
85         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
86         "private": false,
87         "name": "reader",
88         "owner": "Ext.data.Association",
89         "doc": "<p>A special reader to read associated data</p>\n",
90         "linenr": 132,
91         "html_filename": "Association.html"
92       }
93     ],
94     "method": [
95       {
96         "deprecated": null,
97         "alias": null,
98         "href": "Association.html#Ext-data-Association-method-constructor",
99         "tagname": "method",
100         "protected": false,
101         "shortDoc": "Creates the Association object. ...",
102         "static": false,
103         "params": [
104           {
105             "type": "Object",
106             "optional": true,
107             "doc": "<p>(optional) Config object.</p>\n",
108             "name": "config"
109           }
110         ],
111         "private": false,
112         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
113         "doc": "<p>Creates the Association object.</p>\n",
114         "owner": "Ext.data.Association",
115         "name": "Association",
116         "html_filename": "Association.html",
117         "return": {
118           "type": "Object",
119           "doc": "\n"
120         },
121         "linenr": 170
122       },
123       {
124         "deprecated": null,
125         "alias": null,
126         "protected": false,
127         "tagname": "method",
128         "href": "Association.html#Ext-data-Association-method-getReader",
129         "shortDoc": "Get a specialized reader for reading associated data ...",
130         "static": false,
131         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
132         "private": false,
133         "params": [
134
135         ],
136         "name": "getReader",
137         "owner": "Ext.data.Association",
138         "doc": "<p>Get a specialized reader for reading associated data</p>\n",
139         "linenr": 214,
140         "return": {
141           "type": "Ext.data.reader.Reader",
142           "doc": "<p>The reader, null if not supplied</p>\n"
143         },
144         "html_filename": "Association.html"
145       }
146     ],
147     "property": [
148       {
149         "type": "String",
150         "deprecated": null,
151         "alias": null,
152         "protected": false,
153         "tagname": "property",
154         "href": "Association.html#Ext-data-Association-property-associatedName",
155         "shortDoc": "The name of the model is on the other end of the association (e.g. ...",
156         "static": false,
157         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
158         "private": false,
159         "name": "associatedName",
160         "owner": "Ext.data.Association",
161         "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",
162         "linenr": 202,
163         "html_filename": "Association.html"
164       },
165       {
166         "type": "String",
167         "deprecated": null,
168         "alias": null,
169         "protected": false,
170         "tagname": "property",
171         "href": "Association.html#Ext-data-Association-property-ownerName",
172         "static": false,
173         "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
174         "private": false,
175         "name": "ownerName",
176         "owner": "Ext.data.Association",
177         "doc": "<p>The name of the model that 'owns' the association</p>\n",
178         "linenr": 196,
179         "html_filename": "Association.html"
180       }
181     ],
182     "cssVar": [
183
184     ],
185     "cssMixin": [
186
187     ],
188     "event": [
189
190     ]
191   },
192   "singleton": false,
193   "alias": null,
194   "superclasses": [
195
196   ],
197   "protected": false,
198   "tagname": "class",
199   "mixins": [
200
201   ],
202   "href": "Association.html#Ext-data-Association",
203   "subclasses": [
204     "Ext.data.HasManyAssociation",
205     "Ext.data.BelongsToAssociation"
206   ],
207   "static": false,
208   "author": "Ed Spencer",
209   "component": false,
210   "filename": "/mnt/ebs/nightly/git/SDK/platform/src/data/Association.js",
211   "private": false,
212   "alternateClassNames": [
213
214   ],
215   "name": "Ext.data.Association",
216   "doc": "<p>Associations enable you to express relationships between different <a href=\"#/api/Ext.data.Model\" rel=\"Ext.data.Model\" class=\"docClass\">Models</a>. Let's say we're\nwriting an ecommerce system where Users can make Orders - there's a relationship between these Models that we can\nexpress like this:</p>\n\n\n\n\n<pre><code>Ext.define('User', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'name', 'email'],\n\n    hasMany: {model: 'Order', name: 'orders'}\n});\n\nExt.define('Order', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'user_id', 'status', 'price'],\n\n    belongsTo: 'User'\n});\n</code></pre>\n\n\n\n\n<p>We've set up two models - User and Order - and told them about each other. You can set up as many associations on\neach Model as you need using the two default types - <a href=\"#/api/Ext.data.HasManyAssociation\" rel=\"Ext.data.HasManyAssociation\" class=\"docClass\">hasMany</a> and\n<a href=\"#/api/Ext.data.BelongsToAssociation\" rel=\"Ext.data.BelongsToAssociation\" class=\"docClass\">belongsTo</a>. There's much more detail on the usage of each of those inside their\ndocumentation pages. If you're not familiar with Models already, <a href=\"#/api/Ext.data.Model\" rel=\"Ext.data.Model\" class=\"docClass\">there is plenty on those too</a>.</p>\n\n\n\n\n<p><u>Further Reading</u></p>\n\n\n\n\n<ul style=\"list-style-type: disc; padding-left: 20px;\">\n  <li><a href=\"#/api/Ext.data.HasManyAssociation\" rel=\"Ext.data.HasManyAssociation\" class=\"docClass\">hasMany associations</a>\n  <li><a href=\"#/api/Ext.data.BelongsToAssociation\" rel=\"Ext.data.BelongsToAssociation\" class=\"docClass\">belongsTo associations</a>\n  <li><a href=\"#/api/Ext.data.Model\" rel=\"Ext.data.Model\" class=\"docClass\">using Models</a>\n</ul>\n\n\n<p><b>Self association models</b></p>\n\n<p>We can also have models that create parent/child associations between the same type. Below is an example, where\ngroups can be nested inside other groups:</p>\n\n\n<pre><code>\n// Server Data\n{\n    \"groups\": {\n        \"id\": 10,\n        \"parent_id\": 100,\n        \"name\": \"Main Group\",\n        \"parent_group\": {\n            \"id\": 100,\n            \"parent_id\": null,\n            \"name\": \"Parent Group\"\n        },\n        \"child_groups\": [{\n            \"id\": 2,\n            \"parent_id\": 10,\n            \"name\": \"Child Group 1\"\n        },{\n            \"id\": 3,\n            \"parent_id\": 10,\n            \"name\": \"Child Group 2\"\n        },{\n            \"id\": 4,\n            \"parent_id\": 10,\n            \"name\": \"Child Group 3\"\n        }]\n    }\n}\n\n// Client code\nExt.define('Group', {\n    extend: 'Ext.data.Model',\n    fields: ['id', 'parent_id', 'name'],\n    proxy: {\n        type: 'ajax',\n        url: 'data.json',\n        reader: {\n            type: 'json',\n            root: 'groups'\n        }\n    },\n    associations: [{\n        type: 'hasMany',\n        model: 'Group',\n        primaryKey: 'id',\n        foreignKey: 'parent_id',\n        autoLoad: true,\n        associationKey: 'child_groups' // read child data from child_groups\n    }, {\n        type: 'belongsTo',\n        model: 'Group',\n        primaryKey: 'id',\n        foreignKey: 'parent_id',\n        autoLoad: true,\n        associationKey: 'parent_group' // read parent data from parent_group\n    }]\n});\n\n\nExt.onReady(function(){\n    \n    Group.load(10, {\n        success: function(group){\n            console.log(group.getGroup().get('name'));\n            \n            group.groups().each(function(rec){\n                console.log(rec.get('name'));\n            });\n        }\n    });\n    \n});\n</code></pre>\n\n",
217   "mixedInto": [
218
219   ],
220   "linenr": 1,
221   "xtypes": [
222
223   ],
224   "html_filename": "Association.html",
225   "extends": "Object"
226 });