Represents a single table in a database schema.
Can either be populated using the reflection API's or by incrementally building an instance using methods.
Once created TableSchema instances can be added to Schema\Collection objects. They can also be converted into SQL using the createSql(), dropSql() and truncateSql() methods.
string
'cascade'
string
'noAction'
string
'restrict'
string
'setDefault'
string
'setNull'
string
'foreign'
string
'primary'
string
'unique'
string
'fulltext'
string
'index'
integer
4294967295
integer
16777215
integer
255
TYPE_BIGINTEGER
, TYPE_BINARY
, TYPE_BOOLEAN
, TYPE_DATE
, TYPE_DATETIME
, TYPE_DECIMAL
, TYPE_FLOAT
, TYPE_INTEGER
, TYPE_JSON
, TYPE_SMALLINTEGER
, TYPE_STRING
, TYPE_TEXT
, TYPE_TIME
, TYPE_TIMESTAMP
, TYPE_TINYINTEGER
, TYPE_UUID
array
array
The valid keys that can be used in a column definition.
$_columns
protected array
$_constraints
protected array
array
The valid keys that can be used in an index definition.
$_indexes
protected array
$_options
protected array
$_table
protected string
$_temporary
protected boolean
$_typeMap
protected array
array
array
array
array
Returns the base type name for the provided column. This represent the database type a more complex class is based upon.
Sets the type of a column, or returns its current type if none is passed.
Returns an array where the keys are the column names in the schema and the values the database type they have.
__construct( string $table , array $columns [] )
Constructor.
$table
$columns
optional [] _checkForeignKey( array $attrs )
Helper method to check/validate foreign keys.
$attrs
Cake\Database\Exception
addColumn( string $name , array $attrs )
Add a column to the table.
$name
$attrs
Cake\Datasource\SchemaInterface::addColumn()
addConstraint( string $name , array $attrs )
Add a constraint.
$name
$attrs
Cake\Database\Exception
Cake\Database\Schema\TableSchemaInterface::addConstraint()
addConstraintSql( Cake\Database\Connection $connection )
Generate the SQL statements to add the constraints to the table
Cake\Database\Connection
$connection
Cake\Database\Schema\SqlGeneratorInterface::addConstraintSql()
addIndex( string $name , array $attrs )
Add an index.
$name
$attrs
Cake\Database\Exception
Cake\Database\Schema\TableSchemaInterface::addIndex()
baseColumnType( string $column )
Returns the base type name for the provided column. This represent the database type a more complex class is based upon.
$column
Cake\Datasource\SchemaInterface::baseColumnType()
column( string $name )
Get column data in the table.
$name
columnType( string $name , string|null $type null )
Sets the type of a column, or returns its current type if none is passed.
$name
$type
optional null columns( )
Get the column names in the table.
Cake\Datasource\SchemaInterface::columns()
constraint( string $name )
Read information about a constraint based on name.
$name
constraints( )
Get the names of all the constraints in the table.
Cake\Database\Schema\TableSchemaInterface::constraints()
createSql( Cake\Database\Connection $connection )
Generate the SQL to create the Table.
Cake\Database\Connection
$connection
List of SQL statements to create the table and the required indexes.
Cake\Database\Schema\SqlGeneratorInterface::createSql()
defaultValues( )
Get a hash of columns and their default values.
Cake\Datasource\SchemaInterface::defaultValues()
dropConstraint( string $name )
Remove a constraint.
$name
Cake\Database\Schema\TableSchemaInterface::dropConstraint()
dropConstraintSql( Cake\Database\Connection $connection )
Generate the SQL statements to drop the constraints to the table
Cake\Database\Connection
$connection
Cake\Database\Schema\SqlGeneratorInterface::dropConstraintSql()
dropSql( Cake\Database\Connection $connection )
Generate the SQL to drop a table.
Cake\Database\Connection
$connection
Cake\Database\Schema\SqlGeneratorInterface::dropSql()
getColumn( string $name )
Get column data in the table.
$name
Cake\Datasource\SchemaInterface::getColumn()
getColumnType( string $name )
Returns column type or null if a column does not exist.
$name
Cake\Datasource\SchemaInterface::getColumnType()
getConstraint( string $name )
Read information about a constraint based on name.
$name
Cake\Database\Schema\TableSchemaInterface::getConstraint()
getIndex( string $name )
Read information about an index based on name.
$name
Cake\Database\Schema\TableSchemaInterface::getIndex()
getOptions( )
Gets the options for a table.
Cake\Datasource\SchemaInterface::getOptions()
hasAutoincrement( )
Check whether or not a table has an autoIncrement column defined.
Cake\Database\Schema\TableSchemaInterface::hasAutoincrement()
hasColumn( string $name )
Returns true if a column exists in the schema.
$name
Cake\Datasource\SchemaInterface::hasColumn()
index( string $name )
Read information about an index based on name.
$name
indexes( )
Get the names of all the indexes in the table.
Cake\Database\Schema\TableSchemaInterface::indexes()
isNullable( string $name )
Check whether or not a field is nullable
$name
Cake\Datasource\SchemaInterface::isNullable()
isTemporary( )
Gets whether the table is temporary in the database.
Cake\Database\Schema\TableSchemaInterface::isTemporary()
name( )
Get the name of the table.
Cake\Datasource\SchemaInterface::name()
options( array|null $options null )
Get/set the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
$options
optional null primaryKey( )
Get the column(s) used for the primary key.
Column name(s) for the primary key. An empty list will be returned when the table has no primary key.
Cake\Database\Schema\TableSchemaInterface::primaryKey()
removeColumn( string $name )
Remove a column from the table schema.
$name
Cake\Datasource\SchemaInterface::removeColumn()
setColumnType( string $name , string $type )
Sets the type of a column.
$name
$type
Cake\Datasource\SchemaInterface::setColumnType()
setOptions( array $options )
Sets the options for a table.
$options
Cake\Datasource\SchemaInterface::setOptions()
setTemporary( boolean $temporary )
Sets whether the table is temporary in the database.
$temporary
Cake\Database\Schema\TableSchemaInterface::setTemporary()
temporary( boolean|null $temporary null )
Get/Set whether the table is temporary in the database
$temporary
optional null truncateSql( Cake\Database\Connection $connection )
Generate the SQL statements to truncate a table
Cake\Database\Connection
$connection
Cake\Database\Schema\SqlGeneratorInterface::truncateSql()
typeMap( )
Returns an array where the keys are the column names in the schema and the values the database type they have.
Cake\Datasource\SchemaInterface::typeMap()
protected static array
Additional type specific properties.
[ 'string' => [ 'fixed' => null, 'collate' => null, ], 'text' => [ 'collate' => null, ], 'tinyinteger' => [ 'unsigned' => null, ], 'smallinteger' => [ 'unsigned' => null, ], 'integer' => [ 'unsigned' => null, 'autoIncrement' => null, ], 'biginteger' => [ 'unsigned' => null, 'autoIncrement' => null, ], 'decimal' => [ 'unsigned' => null, ], 'float' => [ 'unsigned' => null, ], ]
protected static array
The valid keys that can be used in a column definition.
[ 'type' => null, 'baseType' => null, 'length' => null, 'precision' => null, 'null' => null, 'default' => null, 'comment' => null, ]
protected static array
The valid keys that can be used in an index definition.
[ 'type' => null, 'columns' => [], 'length' => [], 'references' => [], 'update' => 'restrict', 'delete' => 'restrict', ]
protected static array
Names of the valid constraint types.
[ self::CONSTRAINT_PRIMARY, self::CONSTRAINT_UNIQUE, self::CONSTRAINT_FOREIGN, ]
protected static array
Names of the valid foreign key actions.
[ self::ACTION_CASCADE, self::ACTION_SET_NULL, self::ACTION_SET_DEFAULT, self::ACTION_NO_ACTION, self::ACTION_RESTRICT, ]
protected static array
Names of the valid index types.
[ self::INDEX_INDEX, self::INDEX_FULLTEXT, ]
public static array
Valid column length that can be used with text type columns
[ 'tiny' => self::LENGTH_TINY, 'medium' => self::LENGTH_MEDIUM, 'long' => self::LENGTH_LONG ]
© 2005–2018 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.5/class-Cake.Database.Schema.TableSchema.html