Skip to content
PHP Ecosystem
Explore

TableSchema

API reference › yii › db › TableSchema

classyii\db\TableSchema
Extendsyii\base\BaseObject
Implementsyii\base\Configurable
Since2.0
Sourceframework/db/TableSchema.php
1 subclass

TableSchema represents the metadata of a database table.

PropertyTypeDescriptionDefined by
$columnNames read-onlyarrayList of column names.TableSchema
$columnsColumnSchema[]Column metadata of this table. Default: [].TableSchema
$foreignKeysarrayForeign keys of this table. Default: [].TableSchema
$fullNamestringThe full name of this table, which includes the schema name prefix, if any. Default: null.TableSchema
$namestringThe name of this table. Default: null.TableSchema
$primaryKeystring[]Primary keys of this table. Default: [].TableSchema
$schemaNamestringThe name of the schema that this table belongs to. Default: null.TableSchema
$sequenceNamestring|nullSequence name for the primary key. Default: null.TableSchema
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__unset()Sets an object property to null.yii\base\BaseObject
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
fixPrimaryKey()Manually specifies the primary key for this table.TableSchema
getColumn()Gets the named column metadata.TableSchema
getColumnNames()Returns the names of all columns in this table.TableSchema
hasMethod()Returns a value indicating whether a method is defined.yii\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
public yii\db\ColumnSchema[] $columns = []

Column metadata of this table.

Each array element is a ColumnSchema object, indexed by column names.

public array $foreignKeys = []

Foreign keys of this table.

Each array element is of the following structure:

[
'ForeignTableName',
'fk1' => 'pk1', // pk1 is in foreign table
'fk2' => 'pk2', // if composite foreign key
]
public string $fullName = null

The full name of this table, which includes the schema name prefix, if any.

Note that if the schema name is the same as the default schema name, the schema name will not be included.

public string $name = null

The name of this table.

The schema name is not included. Use $fullName to get the name with schema name prefix.

public string|null $sequenceName = null

Sequence name for the primary key.

Null if no sequence.

public function fixPrimaryKey(string|array $keys): mixed

Manually specifies the primary key for this table.

Parameters

ParameterTypeDescription
$keysstring|arrayThe primary key (can be composite)

Returns

mixed

Throws

public function getColumn(string $name): yii\db\ColumnSchema|null

Gets the named column metadata.

This is a convenient method for retrieving a named column even if it does not exist.

Parameters

ParameterTypeDescription
$namestringColumn name

Returns

ColumnSchema|null: Metadata of the named column. Null if the named column does not exist.

public function getColumnNames(): array

Returns the names of all columns in this table.

Returns

array: List of column names