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
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.
Columns can have several attributes:
type
The type of the column. This should be one of CakePHP's abstract types.length
The length of the column.precision
The number of decimal places to store for float and decimal types.default
The default value of the column.null
Whether or not the column can hold nulls.fixed
Whether or not the column is a fixed length column. This is only present/valid with string columns.unsigned
Whether or not the column is an unsigned column. This is only present/valid for integer, decimal, float columns.In addition to the above keys, the following keys are implemented in some database dialects, but not all:
comment
The comment for the column.$name
$attrs
addConstraint( string $name , array $attrs )
Add a constraint.
Used to add constraints to a table. For example primary keys, unique keys and foreign keys.
type
The type of constraint being added.columns
The columns in the index.references
The table, column a foreign key references.update
The behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'.delete
The behavior on delete. Options are 'restrict', 'setNull', 'cascade', 'noAction'.The default for 'update' & 'delete' is 'cascade'.
$name
$attrs
Cake\Database\Exception
addConstraintSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL statements to add the constraints to the table
Cake\Datasource\ConnectionInterface
$connection
addIndex( string $name , array $attrs )
Add an index.
Used to add indexes, and full text indexes in platforms that support them.
type
The type of index being added.columns
The columns in the index.$name
$attrs
Cake\Database\Exception
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
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 constraint( string $name )
Read information about a constraint based on name.
$name
constraints( )
Get the names of all the constraints in the table.
createSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL to create the Table.
Uses the connection to access the schema dialect to generate platform specific SQL.
Cake\Datasource\ConnectionInterface
$connection
List of SQL statements to create the table and the required indexes.
defaultValues( )
Get a hash of columns and their default values.
dropConstraint( string $name )
Remove a constraint.
$name
dropConstraintSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL statements to drop the constraints to the table
Cake\Datasource\ConnectionInterface
$connection
dropSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL to drop a table.
Uses the connection to access the schema dialect to generate platform specific SQL.
Cake\Datasource\ConnectionInterface
$connection
getOptions( )
Gets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
hasAutoincrement( )
Check whether or not a table has an autoIncrement column defined.
index( string $name )
Read information about an index based on name.
$name
isNullable( string $name )
Check whether or not a field is nullable
Missing columns are nullable.
$name
isTemporary( )
Gets whether the table is temporary in the database.
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.
setOptions( array $options )
Sets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
$options
setTemporary( boolean $temporary )
Sets whether the table is temporary in the database.
$temporary
temporary( boolean|null $temporary null )
Get/Set whether the table is temporary in the database
$temporary
optional null truncateSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL statements to truncate a table
Cake\Datasource\ConnectionInterface
$connection
typeMap( )
Returns an array where the keys are the column names in the schema and the values the database type they have.
protected static array
Additional type specific properties.
[ 'string' => [ 'fixed' => null, 'collate' => null, ], 'text' => [ 'collate' => 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–2017 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.4/class-Cake.Database.Schema.TableSchema.html