create() public method

Wrap Idiorm's create method to return an empty instance of the class associated with this wrapper instead of the raw ORM class.
public create ( $data = null )
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;
 }