How can I map a single char column in Doctrine 2, using annotations? I would like to have a char type, instead a single char string.
You can always use the string type with the fixed option:
/**
* @Column(type="string", length=2, options={"fixed" = true})
*/
protected $country;
The above code snippet produces the following SQL:
`country` char(2) NOT NULL,
Doctrine doesn't have a CHAR type defined out of the box, however it does allow you to define custom types, which you could use to create a 'char' type to use in annotations.
The Doctrine documentation has an example of this: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#custom-mapping-types
You might end up providing your own full-column definition:
/**
* @Column(type="string", columnDefinition="CHAR(2) NOT NULL")
*/
protected $country = null;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With