Column
in package
Read onlyYes
FinalYes
Attribute for mapping a property in an entity to a database column.
#[Entity(name: 'my_entity']
final class MyEntity {
#[Column(name: 'my_column', type: ColumnType::String, default: '')]
public string $myColumn = '';
}
A property can be typed as a backed enum instead of a plain scalar by setting enumType to
the enum's class-string. The column itself still stores the enum's scalar backing value
(declare type/length accordingly), but the property is hydrated to and persisted from the
enum case itself:
enum Status: string {
case Draft = 'draft';
case Published = 'published';
}
#[Entity(name: 'my_entity')]
final class MyEntity {
#[Column(name: 'status', type: ColumnType::String, length: 32, enumType: Status::class)]
public Status $status = Status::Draft;
}
Tags
Attributes
- #[Attribute]
- \Attribute::TARGET_PROPERTY
- #[Consumable]
- $since: '35.0.0'
Table of Contents
Properties
- $default : scalar|BackedEnum|null
- $enumType : BackedEnum>|null
- $length : int|null
- $name : non-empty-lowercase-string
- $nullable : bool
- $type : ColumnType
Methods
- __construct() : mixed
Properties
$default
public
scalar|BackedEnum|null
$default
= null
The default value for the column in the database.
$enumType
public
BackedEnum>|null
$enumType
= null
The backed enum the property is typed as. The column keeps storing the enum's scalar backing value; only the PHP property is the enum case.
$length
public
int|null
$length
= null
The length of the column (relevant for Types::STRING)
$name
public
non-empty-lowercase-string
$name
The name of the column in the database.
$nullable
public
bool
$nullable
= false
Whether the column is nullable in the database
$type
public
ColumnType
$type
The type of the column in the database.
Methods
__construct()
public
__construct(string $name, ColumnType $type[, int|null $length = null ][, bool $nullable = false ][, mixed $default = null ][, string|null $enumType = null ]) : mixed
Parameters
- $name : string
- $type : ColumnType
- $length : int|null = null
- $nullable : bool = false
- $default : mixed = null
- $enumType : string|null = null