0 follower


Package system.db.ar
Inheritance class CActiveRecordMetaData
Since 1.0
Source Code framework/db/ar/CActiveRecord.php
CActiveRecordMetaData represents the meta-data for an Active Record class.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined 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

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Constructor. CActiveRecordMetaData
addRelation() Adds a relation. CActiveRecordMetaData
hasRelation() Checks if there is a relation with specified name defined. CActiveRecordMetaData
removeRelation() Deletes a relation with specified name. CActiveRecordMetaData

Property Details

attributeDefaults property
public array $attributeDefaults;

attribute default values

columns property
public array $columns;

table columns

relations property
public array $relations;

list of relations

tableSchema property
public CDbTableSchema $tableSchema;

the table schema information

Method Details

__construct() method
public void __construct(CActiveRecord $model)
$model CActiveRecord the model instance
Source Code: framework/db/ar/CActiveRecord.php#2385 (show)
public function __construct($model)

        throw new 
CDbException(Yii::t('yii','The table "{table}" for active record class "{class}" cannot be found in the database.',
$modelPk=$model->primaryKey())!==null || $table->primaryKey===null)
is_string($table->primaryKey) && isset($table->columns[$table->primaryKey]))
$table->primaryKey as $name)

$table->columns as $name=>$column)
$column->isPrimaryKey && $column->defaultValue!==null)

$model->relations() as $name=>$config)


addRelation() method (available since v1.1.2)
public void addRelation(string $name, array $config)
$name string $name Name of the relation.
$config array $config Relation parameters.
{return} void
Source Code: framework/db/ar/CActiveRecord.php#2435 (show)
public function addRelation($name,$config)
$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));
        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}'=>$this->_modelClassName,'{relation}'=>$name)));

Adds a relation.

$config is an array with three elements: relation type, the related active record class and the foreign key.

hasRelation() method (available since v1.1.2)
public boolean hasRelation(string $name)
$name string $name Name of the relation.
{return} boolean
Source Code: framework/db/ar/CActiveRecord.php#2450 (show)
public function hasRelation($name)
    return isset(

Checks if there is a relation with specified name defined.

removeRelation() method (available since v1.1.2)
public void removeRelation(string $name)
$name string $name
{return} void
Source Code: framework/db/ar/CActiveRecord.php#2462 (show)
public function removeRelation($name)

Deletes a relation with specified name.