I'm using string(32)
instead of integer
for entity id
field (it simulates guid type). But after creating database table from entity ids field type is set to varchar(32)
. I think it's not the best idea, guid
always has length = 32 so char
type will be more appropriate.
Is there a way to tell Doctrine to use char
or the only way is to change it manually in database?
Although the althaus solution works fine I think this one should be the canonical way of doing it:
With annotations:
/**
* @Column(type="string", length=2, options={"fixed" = true})
*/
protected $country;
With YAML (example of both ID and non-ID field):
Your\Nice\Entity:
id:
id:
type: string
length: 32
options:
fixed: true
fields:
country:
type: string
length: 2
options:
fixed: true
- options: Array of additional options:
fixed
: Boolean value to determine if the specified length of a string column should be fixed or varying (applies only for string/binary column and might not be supported by all vendors).
Official documentation
You can tell Doctrine to use vendor specific field types:
/**
* @Column(type="string", columnDefinition="CHAR(2) NOT NULL")
*/
protected $country;
Source
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