Upgrade to ExtJS 4.0.1 - Released 05/18/2011
[extjs.git] / docs / output / Ext.data.Association.js
1 Ext.data.JsonP.Ext_data_Association({
2   "tagname": "class",
3   "name": "Ext.data.Association",
4   "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",
5   "extends": "Object",
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": "ownerModel",
45       "member": "Ext.data.Association",
46       "type": "String",
47       "doc": "<p>The string name of the model that owns the association. Required</p>\n",
48       "private": false,
49       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
50       "linenr": 120,
51       "html_filename": "Association.html",
52       "href": "Association.html#Ext-data-Association-cfg-ownerModel"
53     },
54     {
55       "tagname": "cfg",
56       "name": "primaryKey",
57       "member": "Ext.data.Association",
58       "type": "String",
59       "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",
60       "private": false,
61       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
62       "linenr": 128,
63       "html_filename": "Association.html",
64       "href": "Association.html#Ext-data-Association-cfg-primaryKey",
65       "shortDoc": "The name of the primary key on the associated model. Defaults to 'id'.\nIn general this will be the Ext.data.Model.idP..."
66     },
67     {
68       "tagname": "cfg",
69       "name": "reader",
70       "member": "Ext.data.Association",
71       "type": "Ext.data.reader.Reader",
72       "doc": "<p>A special reader to read associated data</p>\n",
73       "private": false,
74       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
75       "linenr": 134,
76       "html_filename": "Association.html",
77       "href": "Association.html#Ext-data-Association-cfg-reader"
78     }
79   ],
80   "method": [
81     {
82       "tagname": "method",
83       "name": "Association",
84       "member": "Ext.data.Association",
85       "doc": "\n",
86       "params": [
87         {
88           "type": "Object",
89           "name": "config",
90           "doc": "<p>Optional config object</p>\n",
91           "optional": false
92         }
93       ],
94       "return": {
95         "type": "void",
96         "doc": "\n"
97       },
98       "private": false,
99       "static": false,
100       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
101       "linenr": 1,
102       "html_filename": "Association.html",
103       "href": "Association.html#Ext-data-Association-method-constructor",
104       "shortDoc": "\n"
105     },
106     {
107       "tagname": "method",
108       "name": "getReader",
109       "member": "Ext.data.Association",
110       "doc": "<p>Get a specialized reader for reading associated data</p>\n",
111       "params": [
112
113       ],
114       "return": {
115         "type": "Ext.data.reader.Reader",
116         "doc": "<p>The reader, null if not supplied</p>\n"
117       },
118       "private": false,
119       "static": false,
120       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
121       "linenr": 212,
122       "html_filename": "Association.html",
123       "href": "Association.html#Ext-data-Association-method-getReader",
124       "shortDoc": "<p>Get a specialized reader for reading associated data</p>\n"
125     }
126   ],
127   "property": [
128     {
129       "tagname": "property",
130       "name": "associatedName",
131       "member": "Ext.data.Association",
132       "type": "String",
133       "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",
134       "private": false,
135       "static": false,
136       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
137       "linenr": 200,
138       "html_filename": "Association.html",
139       "href": "Association.html#Ext-data-Association-property-associatedName"
140     },
141     {
142       "tagname": "property",
143       "name": "ownerName",
144       "member": "Ext.data.Association",
145       "type": "String",
146       "doc": "<p>The name of the model that 'owns' the association</p>\n",
147       "private": false,
148       "static": false,
149       "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
150       "linenr": 194,
151       "html_filename": "Association.html",
152       "href": "Association.html#Ext-data-Association-property-ownerName"
153     }
154   ],
155   "event": [
156
157   ],
158   "filename": "/Users/nick/Projects/sencha/SDK/platform/src/data/Association.js",
159   "linenr": 1,
160   "html_filename": "Association.html",
161   "href": "Association.html#Ext-data-Association",
162   "cssVar": [
163
164   ],
165   "cssMixin": [
166
167   ],
168   "component": false,
169   "superclasses": [
170
171   ],
172   "subclasses": [
173     "Ext.data.BelongsToAssociation",
174     "Ext.data.HasManyAssociation"
175   ],
176   "mixedInto": [
177
178   ],
179   "allMixins": [
180
181   ]
182 });