Class Column
Schema metadata for a single column
Used by TableSchema when reflecting schema or creating tables.
Method Summary
-
__construct() public
Constructor.
-
getAfter() public
Returns the name of the column to add this column after.
-
getBaseType() public
Get the base type if defined. Will fallback to
typeif not set. -
getCollate() public
Gets the column collation.
-
getComment() public
Gets the column comment.
-
getDefault() public
Gets the default column value.
-
getFixed() public
Gets whether the column is fixed-length.
-
getGenerated() public
Gets generated option for identity columns. Null otherwise
-
getIdentity() public
Gets whether the column is an identity column.
-
getIncrement() public
Gets the column identity increment.
-
getLength() public
Gets the column length.
-
getName() public
Gets the column name.
-
getNull() public
Gets whether the column allows nulls.
-
getOnUpdate() public
Returns the value of the ON UPDATE column function.
-
getPrecision() public
Gets the number precision for decimal or float column.
-
getSrid() public
Gets the column SRID from geometry fields.
-
getType() public
Gets the column type.
-
getUnsigned() public
Gets whether field should be unsigned.
-
getValidOptions() protected
Gets all allowed options. Each option must have a corresponding
setFoomethod. -
isFixed() public
Is the column fixed-length?
-
isIdentity() public
Is the column an identity column?
-
isNull() public
Does the column allow nulls?
-
isSigned() public
Should the column be signed?
-
isUnsigned() public
Should the column be unsigned?
-
setAfter() public
Sets the name of the column to add this column after.
-
setAttributes() public
Utility method that maps an array of column attributes to this object's methods.
-
setBaseType() public
Sets the base type of the column.
-
setCollate() public
Sets the column collation.
-
setComment() public
Sets the column comment.
-
setDefault() public
Sets the default column value.
-
setFixed() public
Sets whether the column is fixed-length.
-
setGenerated() public
Sets generated option for identity columns. Ignored otherwise.
-
setIdentity() public
Sets whether the column is an identity column.
-
setIncrement() public
Sets the column identity increment.
-
setLength() public
Sets the column length.
-
setName() public
Sets the column name.
-
setNull() public
Sets whether the column allows nulls.
-
setOnUpdate() public
Sets the 'ON UPDATE' mysql column function.
-
setPrecision() public
Sets the number precision for decimal or float column.
-
setSrid() public
Sets the column SRID for geometry fields.
-
setType() public
Sets the column type.
-
setUnsigned() public
Sets whether field should be unsigned.
-
toArray() public
Convert an index into an array that is compatible with the Column constructor.
Method Detail
__construct() ¶ public
__construct(string $name, string $type, bool $null = null, mixed $default = null, int|null $length = null, bool $identity = false, string|null $generated = null, int|null $precision = null, int|null $increment = null, string|null $after = null, string|null $onUpdate = null, string|null $comment = null, bool|null $unsigned = null, string|null $collate = null, int|null $srid = null, string|null $baseType = null, bool|null $fixed = null)
Constructor.
Parameters
-
string$name Name of the column
-
string$type Type of the column
-
bool$null optional Whether the column allows null values
-
mixed$default optional Default value for the column
-
int|null$length optional Length of the column
-
bool$identity optional Whether the column is an identity column
-
string|null$generated optional Postgres identity option (always|default)
-
int|null$precision optional Precision for decimal or float columns
-
int|null$increment optional Increment for identity columns
-
string|null$after optional Name of the column to add this column after
-
string|null$onUpdate optional MySQL 'ON UPDATE' function
-
string|null$comment optional Comment for the column
-
bool|null$unsigned optional Whether the column is unsigned
-
string|null$collate optional Collation for the column
-
int|null$srid optional SRID for geometry fields
-
string|null$baseType optional The basic schema type if the column type is a complex/custom type.
-
bool|null$fixed optional Whether the column is fixed-length (BINARY vs VARBINARY)
getAfter() ¶ public
getAfter(): string|null
Returns the name of the column to add this column after.
Used by MySQL and MariaDB in ALTER TABLE statements.
Returns
string|nullgetBaseType() ¶ public
getBaseType(): string|null
Get the base type if defined. Will fallback to type if not set.
Used to get the base type of a column when the column type is a complex/custom type.
Returns
string|nullgetFixed() ¶ public
getFixed(): bool|null
Gets whether the column is fixed-length.
Returns
bool|nullgetGenerated() ¶ public
getGenerated(): string|null
Gets generated option for identity columns. Null otherwise
Returns
string|nullgetIdentity() ¶ public
getIdentity(): bool
Gets whether the column is an identity column.
Returns
boolgetIncrement() ¶ public
getIncrement(): int|null
Gets the column identity increment.
Returns
int|nullgetOnUpdate() ¶ public
getOnUpdate(): string|null
Returns the value of the ON UPDATE column function.
Returns
string|nullgetPrecision() ¶ public
getPrecision(): int|null
Gets the number precision for decimal or float column.
For example DECIMAL(5,2), 5 is the length and 2 is the precision,
and the column could store value from -999.99 to 999.99.
Returns
int|nullgetUnsigned() ¶ public
getUnsigned(): bool|null
Gets whether field should be unsigned.
Returns
bool|nullgetValidOptions() ¶ protected
getValidOptions(): array
Gets all allowed options. Each option must have a corresponding setFoo method.
Returns
arraysetAfter() ¶ public
setAfter(string $after): $this
Sets the name of the column to add this column after.
Parameters
-
string$after After
Returns
$thissetAttributes() ¶ public
setAttributes(array<string, mixed> $attributes): $this
Utility method that maps an array of column attributes to this object's methods.
Parameters
-
array<string, mixed>$attributes Attributes
Returns
$thisThrows
RuntimeExceptionsetBaseType() ¶ public
setBaseType(string|null $baseType): $this
Sets the base type of the column.
Used to set the base type of a column when the column type is a complex/custom type.
Parameters
-
string|null$baseType Base type
Returns
$thissetCollate() ¶ public
setCollate(string $collation): $this
Sets the column collation.
Parameters
-
string$collation Collation
Returns
$thissetComment() ¶ public
setComment(string|null $comment): $this
Sets the column comment.
Parameters
-
string|null$comment Comment
Returns
$thissetDefault() ¶ public
setDefault(mixed $default): $this
Sets the default column value.
Parameters
-
mixed$default Default
Returns
$thissetFixed() ¶ public
setFixed(bool $fixed): $this
Sets whether the column is fixed-length.
Used for binary columns to distinguish between BINARY and VARBINARY.
Parameters
-
bool$fixed Fixed
Returns
$thissetGenerated() ¶ public
setGenerated(string|null $generated): $this
Sets generated option for identity columns. Ignored otherwise.
Parameters
-
string|null$generated Generated option
Returns
$thissetIdentity() ¶ public
setIdentity(bool $identity): $this
Sets whether the column is an identity column.
Parameters
-
bool$identity Identity
Returns
$thissetIncrement() ¶ public
setIncrement(int $increment): $this
Sets the column identity increment.
Parameters
-
int$increment Number increment
Returns
$thissetLength() ¶ public
setLength(int|null $length): $this
Sets the column length.
Parameters
-
int|null$length Length
Returns
$thissetName() ¶ public
setName(string $name): $this
Sets the column name.
Parameters
-
string$name Name
Returns
$thissetNull() ¶ public
setNull(bool $null): $this
Sets whether the column allows nulls.
Parameters
-
bool$null Null
Returns
$thissetOnUpdate() ¶ public
setOnUpdate(string $update): $this
Sets the 'ON UPDATE' mysql column function.
Used by MySQL and MariaDB in ALTER TABLE statements.
Parameters
-
string$update On Update function
Returns
$thissetPrecision() ¶ public
setPrecision(int|null $precision): $this
Sets the number precision for decimal or float column.
For example DECIMAL(5,2), 5 is the length and 2 is the precision,
and the column could store value from -999.99 to 999.99.
Parameters
-
int|null$precision Number precision
Returns
$thissetSrid() ¶ public
setSrid(int $srid): $this
Sets the column SRID for geometry fields.
Parameters
-
int$srid SRID
Returns
$thissetType() ¶ public
setType(string $type): $this
Sets the column type.
Type names are not validated, as drivers and dialects may implement platform specific types that are not known by cakephp.
Drivers are expected to handle unknown types gracefully.
Parameters
-
string$type Column type
Returns
$thissetUnsigned() ¶ public
setUnsigned(bool $unsigned): $this
Sets whether field should be unsigned.
Parameters
-
bool$unsigned Signed
Returns
$thistoArray() ¶ public
toArray(): array
Convert an index into an array that is compatible with the Column constructor.
Returns
array