TableSchema
API reference › yii › db › TableSchema
1 subclass
TableSchema represents the metadata of a database table.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$columnNames read-only | array | List of column names. | TableSchema |
$columns | ColumnSchema[] | Column metadata of this table. Default: []. | TableSchema |
$foreignKeys | array | Foreign keys of this table. Default: []. | TableSchema |
$fullName | string | The full name of this table, which includes the schema name prefix, if any. Default: null. | TableSchema |
$name | string | The name of this table. Default: null. | TableSchema |
$primaryKey | string[] | Primary keys of this table. Default: []. | TableSchema |
$schemaName | string | The name of the schema that this table belongs to. Default: null. | TableSchema |
$sequenceName | string| | Sequence name for the primary key. Default: null. | TableSchema |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
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\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
Property details
Section titled “Property details”$columns
Section titled “$columns ”public yii\db\ColumnSchema[] $columns = []Column metadata of this table.
Each array element is a ColumnSchema object, indexed by column names.
$foreignKeys
Section titled “$foreignKeys ”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]$fullName
Section titled “$fullName ”public string $fullName = nullThe 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.
$name
Section titled “$name ”public string $name = nullThe name of this table.
The schema name is not included. Use $fullName to get the name with schema name prefix.
$sequenceName
Section titled “$sequenceName ”public string|null $sequenceName = nullSequence name for the primary key.
Null if no sequence.
Method details
Section titled “Method details”fixPrimaryKey()
Section titled “fixPrimaryKey() ”public function fixPrimaryKey(string|array $keys): mixedManually specifies the primary key for this table.
Parameters
| Parameter | Type | Description |
|---|---|---|
$keys | string| | The primary key (can be composite) |
Returns
mixed
Throws
yii\base\InvalidArgumentException: if the specified key cannot be found in the table.
getColumn()
Section titled “getColumn() ”public function getColumn(string $name): yii\db\ColumnSchema|nullGets the named column metadata.
This is a convenient method for retrieving a named column even if it does not exist.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Column name |
Returns
ColumnSchema|null: Metadata of the named column. Null if the named column does not exist.
getColumnNames()
Section titled “getColumnNames() ”public function getColumnNames(): arrayReturns the names of all columns in this table.
Returns
array: List of column names