Example #1
0
 /**
  * Factory method that creates model.
  * To prevent metadata refreshing use static model instead of this method if it is possible.
  * This method can be useful when you use named scopes, have alot of work with AR DB criteria, 
  * want to create model with some specific params.
  * 
  * This method not provokes creating of static model by default (if $useAsStaticModel argument = false) 
  * 
  * @todo test it
  * 
  * @param string $tableName
  * @return SmartAR
  */
 public static function create($config, $useAsStaticModel = false)
 {
     if (is_string($config)) {
         # Used in SmartAR::model()
         $tableName = $config;
         $model = new SmartAR(null);
         $ignoreStaticModel = false;
     } else {
         # Can be used to create configured model.
         if (!isset($config['class'])) {
             $config['class'] = __CLASS__;
         }
         $tableName = $config['tableName'];
         unset($config['tableName']);
         if (isset($config['ignoreStaticModel'])) {
             $ignoreStaticModel = $config['ignoreStaticModel'];
             unset($config['ignoreStaticModel']);
         }
         # second argument is passed to CActiveRecord::__construct(null) as scenario to avoid executing of any logics in constructor
         $model = Yii::createComponent($config, null);
     }
     $model->_tableName = self::$_lastTableName = $tableName;
     $model->refreshMetaData();
     self::$_lastTableName = null;
     //	$model->init(false,$ignoreStaticModel);
     return $model;
 }
Example #2
0
 public function setTableName($tableName)
 {
     $this->_tableName = self::$_lastTableName = $tableName;
     $this->refreshMetaData();
     self::$_lastTableName = null;
 }