Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / Association.html
index 77db257..9ffd746 100644 (file)
@@ -3,8 +3,8 @@
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>The source code</title>
-  <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
-  <script type="text/javascript" src="../prettify/prettify.js"></script>
+  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
   <style type="text/css">
     .highlight { display: block; background-color: #ddd; }
   </style>
 <body onload="prettyPrint(); highlight();">
   <pre class="prettyprint lang-js"><span id='Ext-data-Association'>/**
 </span> * @author Ed Spencer
- * @class Ext.data.Association
- * @extends Object
  *
- * &lt;p&gt;Associations enable you to express relationships between different {@link Ext.data.Model Models}. Let's say we're
+ * Associations enable you to express relationships between different {@link Ext.data.Model Models}. Let's say we're
  * writing an ecommerce system where Users can make Orders - there's a relationship between these Models that we can
- * express like this:&lt;/p&gt;
+ * express like this:
  *
-&lt;pre&gt;&lt;code&gt;
-Ext.define('User', {
-    extend: 'Ext.data.Model',
-    fields: ['id', 'name', 'email'],
-
-    hasMany: {model: 'Order', name: 'orders'}
-});
-
-Ext.define('Order', {
-    extend: 'Ext.data.Model',
-    fields: ['id', 'user_id', 'status', 'price'],
-
-    belongsTo: 'User'
-});
-&lt;/code&gt;&lt;/pre&gt;
+ *     Ext.define('User', {
+ *         extend: 'Ext.data.Model',
+ *         fields: ['id', 'name', 'email'],
  *
- * &lt;p&gt;We've set up two models - User and Order - and told them about each other. You can set up as many associations on
- * each Model as you need using the two default types - {@link Ext.data.HasManyAssociation hasMany} and
- * {@link Ext.data.BelongsToAssociation belongsTo}. There's much more detail on the usage of each of those inside their
- * documentation pages. If you're not familiar with Models already, {@link Ext.data.Model there is plenty on those too}.&lt;/p&gt;
+ *         hasMany: {model: 'Order', name: 'orders'}
+ *     });
  *
- * &lt;p&gt;&lt;u&gt;Further Reading&lt;/u&gt;&lt;/p&gt;
+ *     Ext.define('Order', {
+ *         extend: 'Ext.data.Model',
+ *         fields: ['id', 'user_id', 'status', 'price'],
  *
- * &lt;ul style=&quot;list-style-type: disc; padding-left: 20px;&quot;&gt;
- *   &lt;li&gt;{@link Ext.data.HasManyAssociation hasMany associations}
- *   &lt;li&gt;{@link Ext.data.BelongsToAssociation belongsTo associations}
- *   &lt;li&gt;{@link Ext.data.Model using Models}
- * &lt;/ul&gt;
- * 
- * &lt;b&gt;Self association models&lt;/b&gt;
- * &lt;p&gt;We can also have models that create parent/child associations between the same type. Below is an example, where
- * groups can be nested inside other groups:&lt;/p&gt;
- * &lt;pre&gt;&lt;code&gt;
-
-// Server Data
-{
-    &quot;groups&quot;: {
-        &quot;id&quot;: 10,
-        &quot;parent_id&quot;: 100,
-        &quot;name&quot;: &quot;Main Group&quot;,
-        &quot;parent_group&quot;: {
-            &quot;id&quot;: 100,
-            &quot;parent_id&quot;: null,
-            &quot;name&quot;: &quot;Parent Group&quot;
-        },
-        &quot;child_groups&quot;: [{
-            &quot;id&quot;: 2,
-            &quot;parent_id&quot;: 10,
-            &quot;name&quot;: &quot;Child Group 1&quot;
-        },{
-            &quot;id&quot;: 3,
-            &quot;parent_id&quot;: 10,
-            &quot;name&quot;: &quot;Child Group 2&quot;
-        },{
-            &quot;id&quot;: 4,
-            &quot;parent_id&quot;: 10,
-            &quot;name&quot;: &quot;Child Group 3&quot;
-        }]
-    }
-}
-
-// Client code
-Ext.define('Group', {
-    extend: 'Ext.data.Model',
-    fields: ['id', 'parent_id', 'name'],
-    proxy: {
-        type: 'ajax',
-        url: 'data.json',
-        reader: {
-            type: 'json',
-            root: 'groups'
-        }
-    },
-    associations: [{
-        type: 'hasMany',
-        model: 'Group',
-        primaryKey: 'id',
-        foreignKey: 'parent_id',
-        autoLoad: true,
-        associationKey: 'child_groups' // read child data from child_groups
-    }, {
-        type: 'belongsTo',
-        model: 'Group',
-        primaryKey: 'id',
-        foreignKey: 'parent_id',
-        autoLoad: true,
-        associationKey: 'parent_group' // read parent data from parent_group
-    }]
-});
-
-
-Ext.onReady(function(){
-    
-    Group.load(10, {
-        success: function(group){
-            console.log(group.getGroup().get('name'));
-            
-            group.groups().each(function(rec){
-                console.log(rec.get('name'));
-            });
-        }
-    });
-    
-});
- * &lt;/code&gt;&lt;/pre&gt;
+ *         belongsTo: 'User'
+ *     });
+ *
+ * We've set up two models - User and Order - and told them about each other. You can set up as many associations on
+ * each Model as you need using the two default types - {@link Ext.data.HasManyAssociation hasMany} and {@link
+ * Ext.data.BelongsToAssociation belongsTo}. There's much more detail on the usage of each of those inside their
+ * documentation pages. If you're not familiar with Models already, {@link Ext.data.Model there is plenty on those too}.
+ *
+ * **Further Reading**
+ *
+ *   - {@link Ext.data.HasManyAssociation hasMany associations}
+ *   - {@link Ext.data.BelongsToAssociation belongsTo associations}
+ *   - {@link Ext.data.Model using Models}
+ *
+ * # Self association models
+ *
+ * We can also have models that create parent/child associations between the same type. Below is an example, where
+ * groups can be nested inside other groups:
+ *
+ *     // Server Data
+ *     {
+ *         &quot;groups&quot;: {
+ *             &quot;id&quot;: 10,
+ *             &quot;parent_id&quot;: 100,
+ *             &quot;name&quot;: &quot;Main Group&quot;,
+ *             &quot;parent_group&quot;: {
+ *                 &quot;id&quot;: 100,
+ *                 &quot;parent_id&quot;: null,
+ *                 &quot;name&quot;: &quot;Parent Group&quot;
+ *             },
+ *             &quot;child_groups&quot;: [{
+ *                 &quot;id&quot;: 2,
+ *                 &quot;parent_id&quot;: 10,
+ *                 &quot;name&quot;: &quot;Child Group 1&quot;
+ *             },{
+ *                 &quot;id&quot;: 3,
+ *                 &quot;parent_id&quot;: 10,
+ *                 &quot;name&quot;: &quot;Child Group 2&quot;
+ *             },{
+ *                 &quot;id&quot;: 4,
+ *                 &quot;parent_id&quot;: 10,
+ *                 &quot;name&quot;: &quot;Child Group 3&quot;
+ *             }]
+ *         }
+ *     }
+ *
+ *     // Client code
+ *     Ext.define('Group', {
+ *         extend: 'Ext.data.Model',
+ *         fields: ['id', 'parent_id', 'name'],
+ *         proxy: {
+ *             type: 'ajax',
+ *             url: 'data.json',
+ *             reader: {
+ *                 type: 'json',
+ *                 root: 'groups'
+ *             }
+ *         },
+ *         associations: [{
+ *             type: 'hasMany',
+ *             model: 'Group',
+ *             primaryKey: 'id',
+ *             foreignKey: 'parent_id',
+ *             autoLoad: true,
+ *             associationKey: 'child_groups' // read child data from child_groups
+ *         }, {
+ *             type: 'belongsTo',
+ *             model: 'Group',
+ *             primaryKey: 'id',
+ *             foreignKey: 'parent_id',
+ *             associationKey: 'parent_group' // read parent data from parent_group
+ *         }]
+ *     });
+ *
+ *     Ext.onReady(function(){
+ *
+ *         Group.load(10, {
+ *             success: function(group){
+ *                 console.log(group.getGroup().get('name'));
+ *
+ *                 group.groups().each(function(rec){
+ *                     console.log(rec.get('name'));
+ *                 });
+ *             }
+ *         });
+ *
+ *     });
  *
  */
 Ext.define('Ext.data.Association', {
 <span id='Ext-data-Association-cfg-ownerModel'>    /**
-</span>     * @cfg {String} ownerModel The string name of the model that owns the association. Required
+</span>     * @cfg {String} ownerModel (required)
+     * The string name of the model that owns the association.
      */
 
 <span id='Ext-data-Association-cfg-associatedModel'>    /**
-</span>     * @cfg {String} associatedModel The string name of the model that is being associated with. Required
+</span>     * @cfg {String} associatedModel (required)
+     * The string name of the model that is being associated with.
      */
 
 <span id='Ext-data-Association-cfg-primaryKey'>    /**
-</span>     * @cfg {String} primaryKey The name of the primary key on the associated model. Defaults to 'id'.
-     * In general this will be the {@link Ext.data.Model#idProperty} of the Model.
+</span>     * @cfg {String} primaryKey
+     * The name of the primary key on the associated model. In general this will be the
+     * {@link Ext.data.Model#idProperty} of the Model.
      */
     primaryKey: 'id',
 
 <span id='Ext-data-Association-cfg-reader'>    /**
-</span>     * @cfg {Ext.data.reader.Reader} reader A special reader to read associated data
+</span>     * @cfg {Ext.data.reader.Reader} reader
+     * A special reader to read associated data
      */
     
 <span id='Ext-data-Association-cfg-associationKey'>    /**
-</span>     * @cfg {String} associationKey The name of the property in the data to read the association from.
-     * Defaults to the name of the associated model.
+</span>     * @cfg {String} associationKey
+     * The name of the property in the data to read the association from. Defaults to the name of the associated model.
      */
 
     defaultReaderType: 'json',
@@ -186,7 +181,7 @@ Ext.define('Ext.data.Association', {
 
 <span id='Ext-data-Association-method-constructor'>    /**
 </span>     * Creates the Association object.
-     * @param {Object} config (optional) Config object.
+     * @param {Object} [config] Config object.
      */
     constructor: function(config) {
         Ext.apply(this, config);
@@ -211,15 +206,14 @@ Ext.define('Ext.data.Association', {
         this.associatedModel = associatedModel;
 
 <span id='Ext-data-Association-property-ownerName'>        /**
-</span>         * The name of the model that 'owns' the association
-         * @property ownerName
-         * @type String
+</span>         * @property {String} ownerName
+         * The name of the model that 'owns' the association
          */
 
 <span id='Ext-data-Association-property-associatedName'>        /**
-</span>         * The name of the model is on the other end of the association (e.g. if a User model hasMany Orders, this is 'Order')
-         * @property associatedName
-         * @type String
+</span>         * @property {String} associatedName
+         * The name of the model is on the other end of the association (e.g. if a User model hasMany Orders, this is
+         * 'Order')
          */
 
         Ext.applyIf(this, {