You shouldn't need to interact with this class directly. It is used internally by the Model base class.
Inheritance: extends Granada\ORM
Example #1
0
 /**
  *
  * Attempts to execute any relationship defined for eager loading
  *
  * @param Orm\Wrapper $orm
  */
 public static function hydrate($orm, &$results, $return_result_set = false)
 {
     if (count($results) > 0) {
         foreach ($orm->relationships as $include) {
             $relationship = false;
             $relationship_with = null;
             $relationship_args = array();
             if (is_array($include)) {
                 $relationship = key($include);
                 if (isset($include[$relationship]['with'])) {
                     $relationship_with = $include[$relationship]['with'];
                     unset($include[$relationship]['with']);
                 }
                 $relationship_args = $include[$relationship];
             } else {
                 $relationship = $include;
             }
             if ($pos = strpos($relationship, '.')) {
                 $relationship_with = substr($relationship, $pos + 1, strlen($relationship));
                 $relationship = substr($relationship, 0, $pos);
                 $relationship_args = array();
             }
             $relationship = array('name' => $relationship, 'with' => $relationship_with, 'args' => (array) $relationship_args);
             // check if relationship exists on the model
             $model = $orm->create();
             if (!method_exists($model, $relationship['name'])) {
                 throw new Exception("Attempting to eager load [{$relationship['name']}], but the relationship is not defined.", '500');
             }
             self::eagerly($model, $results, $relationship, $return_result_set);
         }
     }
     return $results;
 }
Example #2
0
 /**
  * Factory method used to acquire instances of the given class.
  * The class name should be supplied as a string, and the class
  * should already have been loaded by PHP (or a suitable autoloader
  * should exist). This method actually returns a wrapped ORM object
  * which allows a database query to be built. The wrapped ORM object is
  * responsible for returning instances of the correct class when
  * its find_one or find_many methods are called.
  */
 public static function factory($class_name, $connection_name = null)
 {
     $class_name = self::$auto_prefix_models . $class_name;
     $table_name = self::_get_table_name($class_name);
     if ($connection_name == null) {
         $connection_name = self::_get_static_property($class_name, '_connection_name', Orm\Wrapper::DEFAULT_CONNECTION);
     }
     $wrapper = Orm\Wrapper::for_table($table_name, $connection_name);
     $wrapper->set_class_name($class_name);
     $wrapper->use_id_column(self::_get_id_column_name($class_name));
     $wrapper->resultSetClass = $class_name::$resultSetClass;
     return $wrapper;
 }