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'
int
4294967295
int
16777215
int
255
string
'biginteger'
string
'binary'
string
'binaryuuid'
string
'boolean'
string
'char'
string
'date'
string
'datetime'
string
'datetimefractional'
string
'decimal'
string
'float'
string
'integer'
string
'json'
string
'smallinteger'
string
'string'
string
'text'
string
'time'
string
'timestamp'
string
'timestampfractional'
string
'timestamptimezone'
string
'tinyinteger'
string
'uuid'
array
Additional type specific properties.
array
The valid keys that can be used in a column definition.
array
Columns in the table.
array
Constraints in the table.
array
The valid keys that can be used in an index definition.
array
Indexes in the table.
array
Options for the table.
string
The name of the table
bool
Whether or not the table is temporary
array
A map with columns to types
array
Names of the valid constraint types.
array
Names of the valid foreign key actions.
array
Names of the valid index types.
array
Valid column length that can be used with text type columns
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.
string
$table The table name.
array
$columns optional The list of columns for the schema.
__debugInfo()
Returns an array of the table schema.
array
_checkForeignKey(array $attrs)
Helper method to check/validate foreign keys.
array
$attrs Attributes to set.
array
Cake\Database\Exception
addColumn(string $name, mixed $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.string
$name The name of the column
string|array
$attrs The attributes for the column or the type name.
$this
addConstraint(string $name, mixed $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'.
string
$name The name of the constraint.
array|string
$attrs The attributes for the constraint. If string it will be used as type
.
$this
Cake\Database\Exception
addConstraintSql(\Cake\Database\Connection $connection)
Generate the SQL statements to add the constraints to the table
\Cake\Database\Connection
$connection The connection to generate SQL for.
array
SQL to add the constraints.
addIndex(string $name, mixed $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.string
$name The name of the index.
array|string
$attrs The attributes for the index. If string it will be used as type
.
$this
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.
string
$column The column name to get the base type from
string|null
The base type name
columns()
Get the column names in the table.
string[]
constraints()
Get the names of all the constraints in the table.
string[]
createSql(\Cake\Database\Connection $connection)
Generate the SQL to create the Table.
Uses the connection to access the schema dialect to generate platform specific SQL.
\Cake\Database\Connection
$connection The connection to generate SQL for.
array
List of SQL statements to create the table and the required indexes.
defaultValues()
Get a hash of columns and their default values.
array
dropConstraint(string $name)
Remove a constraint.
string
$name Name of the constraint to remove
$this
dropConstraintSql(\Cake\Database\Connection $connection)
Generate the SQL statements to drop the constraints to the table
\Cake\Database\Connection
$connection The connection to generate SQL for.
array
SQL to drop a table.
dropSql(\Cake\Database\Connection $connection)
Generate the SQL to drop a table.
Uses the connection to access the schema dialect to generate platform specific SQL.
\Cake\Database\Connection
$connection The connection to generate SQL for.
array
SQL to drop a table.
getColumn(string $name)
Get column data in the table.
string
$name The column name.
array|null
Column data or null.
getColumnType(string $name)
Returns column type or null if a column does not exist.
string
$name The column to get the type of.
string|null
getConstraint(string $name)
Read information about a constraint based on name.
string
$name The name of the constraint.
array|null
Array of constraint data, or null
getIndex(string $name)
Read information about an index based on name.
string
$name The name of the index.
array|null
Array of index data, or null
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.
array
An array of options.
getPrimaryKey()
Get the column(s) used for the primary key.
array
Column name(s) for the primary key. An empty list will be returned when the table has no primary key.
hasAutoincrement()
Check whether or not a table has an autoIncrement column defined.
bool
hasColumn(string $name)
Returns true if a column exists in the schema.
string
$name Column name.
bool
indexes()
Get the names of all the indexes in the table.
string[]
isNullable(string $name)
Check whether or not a field is nullable
Missing columns are nullable.
string
$name The column to get the type of.
bool
Whether or not the field is nullable.
isTemporary()
Gets whether the table is temporary in the database.
bool
The current temporary setting.
name()
Get the name of the table.
string
primaryKey()
Get the column(s) used for the primary key.
array
Column name(s) for the primary key. An empty list will be returned when the table has no primary key.
removeColumn(string $name)
Remove a column from the table schema.
If the column is not defined in the table, no error will be raised.
string
$name The name of the column
$this
setColumnType(string $name, string $type)
Sets the type of a column.
string
$name The column to set the type of.
string
$type The type to set the column to.
$this
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.
array
$options The options to set, or null to read options.
$this
setTemporary(bool $temporary)
Sets whether the table is temporary in the database.
bool
$temporary Whether or not the table is to be temporary.
$this
truncateSql(\Cake\Database\Connection $connection)
Generate the SQL statements to truncate a table
\Cake\Database\Connection
$connection The connection to generate SQL for.
array
SQL to truncate a table.
typeMap()
Returns an array where the keys are the column names in the schema and the values the database type they have.
array
Additional type specific properties.
array
The valid keys that can be used in a column definition.
array
Columns in the table.
array
Constraints in the table.
array
The valid keys that can be used in an index definition.
array
Indexes in the table.
array
Options for the table.
array
The name of the table
string
Whether or not the table is temporary
bool
A map with columns to types
array
Names of the valid constraint types.
array
Names of the valid foreign key actions.
array
Names of the valid index types.
array
Valid column length that can be used with text type columns
array
© 2005–present 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/4.1/class-Cake.Database.Schema.TableSchema.html