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 Table instances can be added to Schema\Collection objects. They can also be converted into SQL using the createSql(), dropSql() and truncateSql() methods.
__construct( string $table , array $columns [] )
Constructor.
$table
$columns
optional [] _checkForeignKey( array $attrs )
Helper method to check/validate foreign keys.
$attrs
array
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
mixed
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
mixed
Cake\Database\Exception
addConstraintSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL statements to add the constraints to the table
Cake\Datasource\ConnectionInterface
$connection
array
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
mixed
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
string
column( string $name )
Get column data in the table.
$name
array|null
columnType( string $name , string $type null )
Sets the type of a column, or returns its current type if none is passed.
$name
$type
optional null string|null
constraint( string $name )
Read information about a constraint based on name.
$name
array|null
constraints( )
Get the names of all the constraints in the table.
array
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
array
defaultValues( )
Get a hash of columns and their default values.
array
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
array
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
array
hasAutoincrement( )
Check whether or not a table has an autoIncrement column defined.
boolean
index( string $name )
Read information about an index based on name.
$name
array|null
isNullable( string $name )
Check whether or not a field is nullable
Missing columns are nullable.
$name
boolean
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 mixed
primaryKey( )
Get the column(s) used for the primary key.
array
temporary( boolean|null $set null )
Get/Set whether the table is temporary in the database
$set
optional null mixed
truncateSql( Cake\Datasource\ConnectionInterface $connection )
Generate the SQL statements to truncate a table
Cake\Datasource\ConnectionInterface
$connection
array
typeMap( )
Returns an array where the keys are the column names in the schema and the values the database type they have.
array
string | ACTION_CASCADE Foreign key cascade action | 'cascade' |
string | ACTION_NO_ACTION Foreign key no action | 'noAction' |
string | ACTION_RESTRICT Foreign key restrict action | 'restrict' |
string | ACTION_SET_DEFAULT Foreign key restrict default | 'setDefault' |
string | ACTION_SET_NULL Foreign key set null action | 'setNull' |
string | CONSTRAINT_FOREIGN Foreign constraint type | 'foreign' |
string | CONSTRAINT_PRIMARY Primary constraint type | 'primary' |
string | CONSTRAINT_UNIQUE Unique constraint type | 'unique' |
string | INDEX_FULLTEXT Fulltext index type | 'fulltext' |
string | INDEX_INDEX Index - index type | 'index' |
© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Database.Schema.Table.html