[Solar-svn] Revision 2853

pmjones at solarphp.com pmjones at solarphp.com
Fri Oct 12 09:25:32 CDT 2007


updated comments



Modified: trunk/Solar/Model.php
===================================================================
--- trunk/Solar/Model.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Model.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,3 +1,28 @@
 <?php
+/**
+ * 
+ * Top-level abstract class for models in Solar applications.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Mime.php 2826 2007-10-06 15:55:03Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Top-level abstract class for models in Solar applications.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Model
+ * 
+ */
 abstract class Solar_Model extends Solar_Sql_Model {
 }

Modified: trunk/Solar/Sql/Model/Collection.php
===================================================================
--- trunk/Solar/Sql/Model/Collection.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Collection.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -55,6 +55,8 @@
      * @param int|string $key The sequential or associative key value for the
      * record.
      * 
+     * @return Solar_Sql_Model_Record
+     * 
      */
     public function __get($key)
     {
@@ -261,7 +263,8 @@
     
     /**
      * 
-     * ArrayAccess: set a key value; appends to the 
+     * ArrayAccess: set a key value; appends to the array when using []
+     * notation.
      * 
      * @param string $key The requested key.
      * 

Modified: trunk/Solar/Sql/Model/Record/Exception/Invalid.php
===================================================================
--- trunk/Solar/Sql/Model/Record/Exception/Invalid.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Record/Exception/Invalid.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,2 +1,27 @@
 <?php
+/**
+ * 
+ * One or more column properties failed validation.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * One or more column properties failed validation.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ */
 class Solar_Sql_Model_Record_Exception_Invalid extends Solar_Sql_Model_Record_Exception {}
\ No newline at end of file

Modified: trunk/Solar/Sql/Model/Record/Exception.php
===================================================================
--- trunk/Solar/Sql/Model/Record/Exception.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Record/Exception.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,2 +1,27 @@
 <?php
+/**
+ * 
+ * Exception class for records.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Exception class for records.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ */
 class Solar_Sql_Model_Record_Exception extends Solar_Sql_Model_Exception {}
\ No newline at end of file

Modified: trunk/Solar/Sql/Model/Record.php
===================================================================
--- trunk/Solar/Sql/Model/Record.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Record.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -96,7 +96,7 @@
      * 
      * Keys on the relationship name.
      * 
-     * @param array
+     * @var array
      * 
      */
     protected $_related_page = array();
@@ -459,7 +459,7 @@
     
     // -----------------------------------------------------------------
     //
-    // Database operations
+    // Persistence: save, insert, update, delete, refresh.
     //
     // -----------------------------------------------------------------
     
@@ -543,6 +543,36 @@
         }
     }
     
+    /**
+     * 
+     * User-defined pre-save logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _preSave()
+    {
+    }
+    
+    /**
+     * 
+     * User-defined post-save logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _postSave()
+    {
+    }
+    
+    /**
+     * 
+     * Inserts the current record into the database, making calls to pre- and
+     * post-insert logic.
+     * 
+     * @return void
+     * 
+     */
     protected function _insert()
     {
         try {
@@ -558,6 +588,36 @@
         }
     }
     
+    /**
+     * 
+     * User-defined pre-insert logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _preInsert()
+    {
+    }
+    
+    /**
+     * 
+     * User-defined post-insert logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _postInsert()
+    {
+    }
+    
+    /**
+     * 
+     * Updates the current record at the database, making calls to pre- and
+     * post-update logic.
+     * 
+     * @return void
+     * 
+     */
     protected function _update()
     {
         try {
@@ -574,80 +634,231 @@
         }
     }
     
-    protected function _preSave()
+    /**
+     * 
+     * User-defined pre-update logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _preUpdate()
     {
     }
     
-    protected function _postSave()
+    /**
+     * 
+     * User-defined post-update logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _postUpdate()
     {
     }
     
-    protected function _preInsert()
+    /**
+     * 
+     * Deletes this record from the database.
+     * 
+     * @return void
+     * 
+     */
+    public function delete()
     {
+        $this->_checkDeleted();
+        $this->_preDelete();
+        $this->_model->delete($this);
+        $this->_postDelete();
     }
     
-    protected function _postInsert()
+    /**
+     * 
+     * User-defined pre-delete logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _preDelete()
     {
     }
     
-    protected function _preUpdate()
+    /**
+     * 
+     * User-defined post-delete logic.
+     * 
+     * @return void
+     * 
+     */
+    protected function _postDelete()
     {
     }
     
-    protected function _postUpdate()
+    /**
+     * 
+     * Refreshes data for this record from the database.
+     * 
+     * Note that this does not refresh any related or calculated values.
+     * 
+     * @return void
+     * 
+     */
+    public function refresh()
     {
+        if ($this->_status != 'new') {
+            $primary = $this->_model->primary_col;
+            $result = $this->_model->fetch($this->$primary);
+            $this->load($result);
+            $this->_status = 'clean';
+        }
     }
     
-    protected function _preDelete()
-    {
-    }
+    // -----------------------------------------------------------------
+    // 
+    // Filtering and data invalidation.
+    // 
+    // -----------------------------------------------------------------
     
-    protected function _postDelete()
+    /**
+     * 
+     * Filter the data.
+     * 
+     * @return void
+     * 
+     */
+    public function filter()
     {
+        $this->_preFilter();
+        
+        // create a filter object based on the model's filter class
+        $filter = Solar::factory($this->_model->filter_class);
+        
+        // set filters as specified by the model
+        foreach ($this->_model->filters as $key => $list) {
+            $filter->addChainFilters($key, $list);
+        }
+        
+        // set which elements are required by the table itself
+        foreach ($this->_model->table_cols as $key => $info) {
+            if ($info['autoinc']) {
+                // autoinc are not required
+                $flag = false;
+            } elseif (in_array($key, $this->_model->sequence_cols)) {
+                // auto-sequence are not required
+                $flag = false;
+            } else {
+                // go with the col info
+                $flag = $info['require'];
+            }
+            
+            // set the requirement flag
+            $filter->setChainRequire($key, $flag);
+        }
+        
+        // tell the filter to use the model for locale strings
+        $filter->setChainLocaleObject($this->_model);
+        
+        // apply filters and retain invalids
+        $valid = $filter->applyChain($this);
+        $invalid = $filter->getChainInvalid();
+        
+        // reclaim memory
+        $filter->__destruct();
+        unset($filter);
+        
+        // was it valid?
+        if (! $valid) {
+            $this->_status = 'invalid';
+            $this->_invalid = $invalid;
+            throw $this->_exception('ERR_INVALID', array($this->_invalid));
+        }
+        
+        // post-logic, and done
+        $this->_postFilter();
     }
     
+    /**
+     * 
+     * User-defined logic executed before filters are applied to the record
+     * data.
+     * 
+     * @return void
+     * 
+     */
     protected function _preFilter()
     {
     }
     
+    /**
+     * 
+     * User-defined logic executed after filters are applied to the record
+     * data.
+     * 
+     * @return void
+     * 
+     */
     protected function _postFilter()
     {
     }
     
     /**
      * 
-     * Deletes this record from the database.
+     * Forces one property to be "invalid" and sets a validation failure message
+     * for it.
      * 
+     * @param string $key The property name.
+     * 
+     * @param string $message The validation failure message.
+     * 
      * @return void
      * 
      */
-    public function delete()
+    public function setInvalid($key, $message)
     {
-        $this->_checkDeleted();
-        $this->_preDelete();
-        $this->_model->delete($this);
-        $this->_postDelete();
+        $this->_status = 'invalid';
+        $this->_invalid[$key][] = $message;
     }
     
     /**
      * 
-     * Refreshes data for this record from the database.
+     * Forces multiple properties to be "invalid" and sets validation failure
+     * message for them.
      * 
-     * Note that this does not refresh any related or calculated values.
+     * @param array $list An associative array where the key is the property
+     * name, and the value is a string (or array of strings) of invalidation
+     * messages.
      * 
      * @return void
      * 
      */
-    public function refresh()
+    public function setInvalids($list)
     {
-        if ($this->_status != 'new') {
-            $primary = $this->_model->primary_col;
-            $result = $this->_model->fetch($this->$primary);
-            $this->load($result);
-            $this->_status = 'clean';
+        $this->_status = 'invalid';
+        foreach ($list as $key => $messages) {
+            foreach ((array) $messages as $message) {
+                $this->_invalid[$key][] = $message;
+            }
         }
     }
     
+    /**
+     * 
+     * Returns the validation failure message for one or more properties.
+     * 
+     * @param string $key Return the message for this property; if empty,
+     * returns messages for all invalid properties.
+     * 
+     * @return string|array
+     * 
+     */
+    public function getInvalid($key = null)
+    {
+        if ($key) {
+            return $this->_invalid[$key];
+        } else {
+            return $this->_invalid;
+        }
+    }
+    
     // -----------------------------------------------------------------
     //
     // Record relationships
@@ -733,53 +944,6 @@
     
     /**
      * 
-     * Forces one property to be "invalid" and sets a validation failure message
-     * for it.
-     * 
-     * @param string $key The property name.
-     * 
-     * @param string $message The validation failure message.
-     * 
-     * @return void
-     * 
-     */
-    public function setInvalid($key, $message)
-    {
-        $this->_status = 'invalid';
-        $this->_invalid[$key][] = $message;
-    }
-    
-    public function setInvalids($list)
-    {
-        $this->_status = 'invalid';
-        foreach ($list as $key => $messages) {
-            foreach ((array) $messages as $message) {
-                $this->_invalid[$key][] = $message;
-            }
-        }
-    }
-    
-    /**
-     * 
-     * Returns the validation failure message for one or more properties.
-     * 
-     * @param string $key Return the message for this property; if empty,
-     * returns messages for all invalid properties.
-     * 
-     * @return string|array
-     * 
-     */
-    public function getInvalid($key = null)
-    {
-        if ($key) {
-            return $this->_invalid[$key];
-        } else {
-            return $this->_invalid;
-        }
-    }
-    
-    /**
-     * 
      * Throws an exception if this record status is 'deleted'.
      * 
      * @return void
@@ -795,64 +959,24 @@
         }
     }
     
+    // -----------------------------------------------------------------
+    // 
+    // Automated forms.
+    // 
+    // -----------------------------------------------------------------
+    
     /**
      * 
-     * Filter the data.
+     * Returns a Solar_Form object pre-populated with column properties,
+     * values, and filters ready for processing (all based on the model for
+     * this record).
      * 
-     * @return void
+     * @param array $cols An array of column property names to include in
+     * the form; if empty, uses all columns.
      * 
+     * @return Solar_Form
+     * 
      */
-    public function filter()
-    {
-        $this->_preFilter();
-        
-        // create a filter object based on the model's filter class
-        $filter = Solar::factory($this->_model->filter_class);
-        
-        // set filters as specified by the model
-        foreach ($this->_model->filters as $key => $list) {
-            $filter->addChainFilters($key, $list);
-        }
-        
-        // set which elements are required by the table itself
-        foreach ($this->_model->table_cols as $key => $info) {
-            if ($info['autoinc']) {
-                // autoinc are not required
-                $flag = false;
-            } elseif (in_array($key, $this->_model->sequence_cols)) {
-                // auto-sequence are not required
-                $flag = false;
-            } else {
-                // go with the col info
-                $flag = $info['require'];
-            }
-            
-            // set the requirement flag
-            $filter->setChainRequire($key, $flag);
-        }
-        
-        // tell the filter to use the model for locale strings
-        $filter->setChainLocaleObject($this->_model);
-        
-        // apply filters and retain invalids
-        $valid = $filter->applyChain($this);
-        $invalid = $filter->getChainInvalid();
-        
-        // reclaim memory
-        $filter->__destruct();
-        unset($filter);
-        
-        // was it valid?
-        if (! $valid) {
-            $this->_status = 'invalid';
-            $this->_invalid = $invalid;
-            throw $this->_exception('ERR_INVALID', array($this->_invalid));
-        }
-        
-        // post-logic, and done
-        $this->_postFilter();
-    }
-    
     public function form($cols = null)
     {
         $array_name = $this->_model->model_name;

Modified: trunk/Solar/Sql/Model/Related/BelongsTo.php
===================================================================
--- trunk/Solar/Sql/Model/Related/BelongsTo.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Related/BelongsTo.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,12 +1,56 @@
 <?php
+/**
+ * 
+ * Represents the characteristics of a relationship where a native model
+ * "belongs to" a foreign model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Represents the characteristics of a relationship where a native model
+ * "belongs to" a foreign model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ */
 class Solar_Sql_Model_Related_BelongsTo extends Solar_Sql_Model_Related {
     
+    /**
+     * 
+     * Sets the relationship type.
+     * 
+     * @return void
+     * 
+     */
     protected function _setType()
     {
         $this->type = 'belongs_to';
     }
     
-    // foreign key is stored in the native model
+    /**
+     * 
+     * Fixes the related column names in the user-defined options **in place**.
+     * 
+     * The foreign key is stored in the **native** model.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     protected function _fixRelatedCol(&$opts)
     {
         $opts['native_col'] = $opts['foreign_key'];

Modified: trunk/Solar/Sql/Model/Related/HasMany.php
===================================================================
--- trunk/Solar/Sql/Model/Related/HasMany.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Related/HasMany.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,12 +1,57 @@
 <?php
+/**
+ * 
+ * Represents the characteristics of a relationship where a native model
+ * "has many" of a foreign model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Represents the characteristics of a relationship where a native model
+ * "has many" of a foreign model.  This includes "has many through" (i.e.,
+ * a many-to-many relationship through an interceding mapping model).
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ */
 class Solar_Sql_Model_Related_HasMany extends Solar_Sql_Model_Related {
     
+    /**
+     * 
+     * Sets the relationship type.
+     * 
+     * @return void
+     * 
+     */
     protected function _setType()
     {
         $this->type = 'has_many';
     }
     
-    // foreign key is stored in the foreign model
+    /**
+     * 
+     * Fixes the related column names in the user-defined options **in place**.
+     * 
+     * The foreign key is stored in the **foreign** model.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     protected function _fixRelatedCol(&$opts)
     {
         $opts['foreign_col'] = $opts['foreign_key'];
@@ -135,6 +180,20 @@
         }
     }
     
+    /**
+     * 
+     * Special-case modification for selections of has-many-through records.
+     * 
+     * @param Solar_Sql_Select $select The selection object to modify.
+     * 
+     * @param Solar_Sql_Select|Solar_Sql_Model_Record $spec If a
+     * Solar_Sql_Select, used as an "inner" select to find the correct native
+     * IDs.  If a Solar_Sql_Model_Record, will find based on the ID of the
+     * record.
+     * 
+     * @return void
+     * 
+     */
     protected function _modSelect($select, $spec)
     {
         // for non-through relationship, go with the parent method

Modified: trunk/Solar/Sql/Model/Related/HasOne.php
===================================================================
--- trunk/Solar/Sql/Model/Related/HasOne.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Related/HasOne.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,12 +1,56 @@
 <?php
+/**
+ * 
+ * Represents the characteristics of a relationship where a native model
+ * "has one" of a foreign model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Represents the characteristics of a relationship where a native model
+ * "has one" of a foreign model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ */
 class Solar_Sql_Model_Related_HasOne extends Solar_Sql_Model_Related {
     
+    /**
+     * 
+     * Sets the relationship type.
+     * 
+     * @return void
+     * 
+     */
     protected function _setType()
     {
         $this->type = 'has_one';
     }
     
-    // foreign key is stored in the foreign model
+    /**
+     * 
+     * Fixes the related column names in the user-defined options **in place**.
+     * 
+     * The foreign key is stored in the **foreign** model.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     protected function _fixRelatedCol(&$opts)
     {
         $opts['foreign_col'] = $opts['foreign_key'];

Modified: trunk/Solar/Sql/Model/Related.php
===================================================================
--- trunk/Solar/Sql/Model/Related.php	2007-10-11 17:44:42 UTC (rev 2852)
+++ trunk/Solar/Sql/Model/Related.php	2007-10-12 14:25:32 UTC (rev 2853)
@@ -1,9 +1,48 @@
 <?php
-// <http://ar.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html>
+/**
+ * 
+ * Abstract class to represent the characteristics of a related model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ * @author Paul M. Jones <pmjones at solarphp.com>
+ * 
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ * 
+ * @version $Id: Exception.php 2440 2007-04-21 14:33:44Z pmjones $
+ * 
+ */
+
+/**
+ * 
+ * Abstract class to represent the characteristics of a related model.
+ * 
+ * @category Solar
+ * 
+ * @package Solar_Sql_Model
+ * 
+ */
 abstract class Solar_Sql_Model_Related extends Solar_Base {
     
+    /**
+     * 
+     * The name of the relationship as defined by the original (native) model.
+     * 
+     * @var string
+     * 
+     */
     public $name;
     
+    /**
+     * 
+     * The type of the relationship as defined by the original (native) model;
+     * e.g., 'has_one', 'belongs_to', 'has_many'.
+     * 
+     * @var string
+     * 
+     */
     public $type;
     
     /**
@@ -44,10 +83,9 @@
     
     /**
      * 
-     * `foreign_class`
-     * : (string) The class name of the foreign model. Default is the first
-     *   matching class for the relationship name, as loaded from the parent
-     *   class stack. Automatically honors single-table inheritance.
+     * The class name of the foreign model. Default is the first
+     * matching class for the relationship name, as loaded from the parent
+     * class stack. Automatically honors single-table inheritance.
      * 
      * 
      * @var string
@@ -57,9 +95,8 @@
     
     /**
      * 
-     * `foreign_table`
-     * : (string) The name of the table for the foreign model. Default is the
-     *   table specified by the foreign model.
+     * The name of the table for the foreign model. Default is the
+     * table specified by the foreign model.
      * 
      * @var string
      * 
@@ -68,9 +105,8 @@
     
     /**
      * 
-     * `foreign_alias`
-     * : (string) Aliases the foreign table to this name. Default is the
-     *   relationship name.
+     * Aliases the foreign table to this name. Default is the
+     * relationship name.
      * 
      * @var string
      * 
@@ -79,10 +115,9 @@
     
     /**
      * 
-     * `foreign_col`
-     * : (string) The name of the column to join with in the *foreign* table.
-     *   This forms one-half of the relationship.  Default is per association
-     *   type.
+     * The name of the column to join with in the *foreign* table.
+     * This forms one-half of the relationship.  Default is per association
+     * type.
      * 
      * @var string
      * 
@@ -100,9 +135,8 @@
     
     /**
      * 
-     * `foreign_inherit_col`
-     * : (string) If the foreign model uses single-table inheritance, this is
-     *   the column where the inheritance value is stored.
+     * If the foreign model uses single-table inheritance, this is
+     * the column where the inheritance value is stored.
      * 
      * 
      * @var string
@@ -112,9 +146,8 @@
     
     /**
      * 
-     * `foreign_inherit_val`
-     * : (string) If the foreign model has an inheritance type, the value of
-     *   that inheritance type (as stored in foreign_inherit_col).
+     * If the foreign model has an inheritance type, the value of
+     * that inheritance type (as stored in foreign_inherit_col).
      * 
      * @var string
      * 
@@ -240,7 +273,7 @@
     
     /**
      * 
-     * There is a virtual element called `foreign_key` that automatically
+     * The virtual element called `foreign_key` automatically
      * populates the `native_col` or `foreign_col` value for you, based on the
      * association type.  This will be used **only** when `native_col` **and**
      * `foreign_col` are not set.
@@ -248,22 +281,45 @@
      * @var string
      * 
      */
-    // public $foreign_key;
+    public $foreign_key;
     
     /**
      * 
-     * There is a virtual element called `through_key` that automatically 
+     * The virtual element `through_key` automatically 
      * populates the 'through_foreign_col' value for you.
      * 
      * @var string.
      * 
      */
-    // public $through_key;
+    public $through_key;
     
+    /**
+     * 
+     * An instance of the native (origin) model that defined this relationship.
+     * 
+     * @var Solar_Sql_Model
+     * 
+     */
     protected $_native_model;
     
+    /**
+     * 
+     * An instance of the foreign (related) model.
+     * 
+     * @var Solar_Sql_Model
+     * 
+     */
     protected $_foreign_model;
     
+    /**
+     * 
+     * Sets the native (origin) model instance.
+     * 
+     * @param Solar_Sql_Model $model The native model instance.
+     * 
+     * @return void
+     * 
+     */
     public function setNativeModel($model)
     {
         $this->_native_model = $model;
@@ -272,12 +328,25 @@
         $this->native_alias = $this->_native_model->model_name;
     }
     
-    // gets the *related* model, not the native model
+    /**
+     * 
+     * Returns the **related** model instance.
+     * 
+     * @return Solar_Sql_Model
+     * 
+     */
     public function getModel()
     {
         return $this->_foreign_model;
     }
     
+    /**
+     * 
+     * Returns the relation characteristics as an array.
+     * 
+     * @return array
+     * 
+     */
     public function toArray()
     {
         $vars = get_object_vars($this);
@@ -291,8 +360,11 @@
     
     /**
      * 
-     * Corrects the relationship definitions.
+     * Loads this relationship object with user-defined characteristics
+     * (options), and corrects them as needed.
      * 
+     * @param array $opts The user-defined options for the relationship.
+     * 
      * @return void
      * 
      */
@@ -317,6 +389,18 @@
         $this->_setRelated($opts);
     }
     
+    /**
+     * 
+     * Creates a new selection object for records on this relationship.
+     * 
+     * @param mixed $spec If an array, treated as params for a select 
+     * statement (where, group, having, etc) for finding the native-model IDs.
+     * If a Record object, the record's primary-key is used for the native-
+     * model ID.
+     * 
+     * @return Solar_Sql_Select
+     * 
+     */
     public function newSelect($spec)
     {
         // specification must be a record, or params for a select
@@ -363,6 +447,20 @@
         return $select;
     }
     
+    /**
+     * 
+     * Modifies the base select statement for the relationship type.
+     * 
+     * @param Solar_Sql_Select $select The selection object to modify.
+     * 
+     * @param Solar_Sql_Select|Solar_Sql_Model_Record $spec If a
+     * Solar_Sql_Select, used as an "inner" select to find the correct native
+     * IDs.  If a Solar_Sql_Model_Record, will find based on the ID of the
+     * record.
+     * 
+     * @return void
+     * 
+     */
     protected function _modSelect($select, $spec)
     {
         // simple belongs_to, has_one, or has_many.
@@ -399,6 +497,16 @@
         }
     }
     
+    /**
+     * 
+     * Sets the foreign model instance based on user-defined relationship
+     * options.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     protected function _setForeignModel($opts)
     {
         // make sure we have at least a base class name
@@ -468,6 +576,16 @@
     }
     
     
+    /**
+     * 
+     * Sets the foreign columns to be selected based on user-defined 
+     * relationship options.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     protected function _setCols($opts)
     {
         // the list of foreign table cols to retrieve
@@ -504,6 +622,16 @@
         }
     }
     
+    /**
+     * 
+     * Sets additional selection clauses ('where', 'having', 'group') for
+     * related records based on user-defined relationship options.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     protected function _setSelect($opts)
     {
         // distinct
@@ -550,9 +678,35 @@
         }
     }
     
+    /**
+     * 
+     * Sets the relationship type.
+     * 
+     * @return void
+     * 
+     */
     abstract protected function _setType();
     
+    /**
+     * 
+     * Fixes the related column names in the user-defined options **in place**.
+     * 
+     * @param array $opts The user-defined relationship options.
+     * 
+     * @return void
+     * 
+     */
     abstract protected function _fixRelatedCol(&$opts);
     
+    /**
+     * 
+     * Sets the characteristics for the related model, table, etc. based on
+     * the user-defined relationship options.
+     * 
+     * @param array $opts The user-defined options for the relationship.
+     * 
+     * @return void
+     * 
+     */
     abstract protected function _setRelated($opts);
 }
\ No newline at end of file




More information about the Solar-svn mailing list