CActiveRecordMetaData

CDbHttpSession

Yii Framework v1.1.10 类参考

CActiveRecordMetaData

system.db.ar
继承 class CActiveRecordMetaData
源自 1.0
版本 $Id: CActiveRecord.php 3533 2012-01-08 22:07:55Z mdomba $
源码 framework/db/ar/CActiveRecord.php
CActiveRecordMetaData表示一个活动记录类的源数据。

公共属性

隐藏继承属性

属性类型描述定义在
attributeDefaults array 属性默认值 CActiveRecordMetaData
columns array 表的列 CActiveRecordMetaData
relations array 关系列表 CActiveRecordMetaData
tableSchema CDbTableSchema 表结构信息 CActiveRecordMetaData

公共方法

隐藏继承方法

方法描述定义在
__construct() 构造函数。 CActiveRecordMetaData
addRelation() 增加一个关系。 CActiveRecordMetaData
hasRelation() 检查是否有一个带有指定名称定义的关系。 CActiveRecordMetaData
removeRelation() 删除一个带有指定名称的关系。 CActiveRecordMetaData

属性详细

attributeDefaults 属性
public array $attributeDefaults;

属性默认值

columns 属性
public array $columns;

表的列

relations 属性
public array $relations;

关系列表

tableSchema 属性
public CDbTableSchema $tableSchema;

表结构信息

方法详细

__construct() 方法
public void __construct(CActiveRecord $model)
$model CActiveRecord 模型实例
源码: framework/db/ar/CActiveRecord.php#2258 (显示)
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();
        if(
is_string($table->primaryKey) && isset($table->columns[$table->primaryKey]))
            
$table->columns[$table->primaryKey]->isPrimaryKey=true;
        else if(
is_array($table->primaryKey))
        {
            foreach(
$table->primaryKey as $name)
            {
                if(isset(
$table->columns[$name]))
                    
$table->columns[$name]->isPrimaryKey=true;
            }
        }
    }
    
$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)
    {
        
$this->addRelation($name,$config);
    }
}

构造函数。

addRelation() 方法 (可用自 v1.1.2)
public void addRelation(string $name, array $config)
$name string $name 关系名称。
$config array $config 相关参数。
{return} void
源码: framework/db/ar/CActiveRecord.php#2307 (显示)
public function addRelation($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($this->_model),'{relation}'=>$name)));
}

增加一个关系。

$config 是一个带有三个元素的数组: 关系类型,相关的活动记录类和外键。

hasRelation() 方法 (可用自 v1.1.2)
public boolean hasRelation(string $name)
$name string $name 关系的名称。
{return} boolean
源码: framework/db/ar/CActiveRecord.php#2322 (显示)
public function hasRelation($name)
{
    return isset(
$this->relations[$name]);
}

检查是否有一个带有指定名称定义的关系。

removeRelation() 方法 (可用自 v1.1.2)
public void removeRelation(string $name)
$name string $name
{return} void
源码: framework/db/ar/CActiveRecord.php#2334 (显示)
public function removeRelation($name)
{
    unset(
$this->relations[$name]);
}

删除一个带有指定名称的关系。

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.