/**
  * Builds a new CDbMetadata object. This object stores all the metadata
  * relative to the given table, extracting more information from the
  * core CDbTableMetadata object that the framework provides.
  *
  * @param CDbMetadataFactory $factory The factory that created this object
  * @param CDbTableSchema $schema the table from which we work on
  */
 public function __construct(CDbMetadataFactory $factory, CDbTableSchema $schema)
 {
     $this->_name = $schema->name;
     $this->_raw_name = $schema->rawName;
     $this->_sequence_name = $schema->sequenceName;
     foreach ($schema->columns as $column) {
         $this->_columns[] = $factory->createDbColumnMetadata($column);
     }
     if (is_array($schema->primaryKey)) {
         $this->_primary_key = new CCompositePrimaryKey($schema->primaryKey, $this->_columns);
     } elseif ($schema->primaryKey !== null) {
         $this->_primary_key = new CSimplePrimaryKey($schema->primaryKey, $this->_columns);
     }
     foreach ($schema->foreignKeys as $foreignKey) {
         $this->_foreign_keys[] = new CForeignKey($foreignKey, $this->_columns);
     }
 }
 /**
  * Generates a new additional metadata information from a given active
  * record model.
  *
  * @param CActiveRecord $record
  * @return IDbMetadata
  */
 public static function getMetadata(CActiveRecord $record)
 {
     $factory = new CDbMetadataFactory();
     return $factory->createDbMetadata($record->getMetaData()->tableSchema);
 }