Package | system.db.ar |
---|---|
Inheritance | class CActiveRecordMetaData |
Since | 1.0 |
Version | $Id$ |
Source Code | framework/db/ar/CActiveRecord.php |
Property | Type | Description | Defined By |
---|---|---|---|
attributeDefaults | array | attribute default values | CActiveRecordMetaData |
columns | array | table columns | CActiveRecordMetaData |
relations | array | list of relations | CActiveRecordMetaData |
tableSchema | CDbTableSchema | the table schema information | CActiveRecordMetaData |
Method | Description | Defined By |
---|---|---|
__construct() | Constructor. | CActiveRecordMetaData |
getValidators() | Returns list of validators | CActiveRecordMetaData |
attribute default values
table columns
list of relations
the table schema information
public void __construct(CActiveRecord $model)
| ||
$model | CActiveRecord | the model instance |
public function __construct($model)
{
$this->_model=$model;
$tableName=$model->tableName();
if(($table=$model->getDbConnection()->getSchema()->getTable($tableName))===null)
throw new CDbException(Yii::t('yii','The table "{table}" for active record class "{class}" cannot be found in the database.',
array('{class}'=>get_class($model),'{table}'=>$tableName)));
if($table->primaryKey===null)
$table->primaryKey=$model->primaryKey();
$this->tableSchema=$table;
$this->columns=$table->columns;
foreach($table->columns as $name=>$column)
{
if(!$column->isPrimaryKey && $column->defaultValue!==null)
$this->attributeDefaults[$name]=$column->defaultValue;
}
foreach($model->relations() as $name=>$config)
{
if(isset($config[0],$config[1],$config[2])) // relation class, AR class, FK
$this->relations[$name]=new $config[0]($name,$config[1],$config[2],array_slice($config,3));
else
throw new CDbException(Yii::t('yii','Active record "{class}" has an invalid configuration for relation "{relation}". It must specify the relation type, the related active record class and the foreign key.',
array('{class}'=>get_class($model),'{relation}'=>$name)));
}
}
Constructor.
public array getValidators()
| ||
{return} | array | list of validators |
public function getValidators()
{
if(!$this->_validators)
$this->_validators=$this->_model->createValidators();
return $this->_validators;
}
Signup or Login in order to comment.