Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zerofill with Doctrine2

It looks like an easy task, but I can't get it done:
How do I define a column to be UNSIGNED ZEROFILL with Doctrine2?

I can't find any information about it in the docs.

Thx for any help!

like image 710
sprain Avatar asked Jun 02 '11 11:06

sprain


2 Answers

Do you need it on database level or is it required only by the application? You could append zeros on the application level:

class MyEntity {
    public function getSomeColumn() {
        return sprintf('%05d', $this->someColumn); // or str_pad(...)
    }
}

However if you really need it on database level then you'll have to annotate the column as a string: @Column(type="string", columnDefinition="UNSIGNED INTEGER(5) ZEROFILL")

like image 162
Crozin Avatar answered Oct 10 '22 04:10

Crozin


The good syntax is :

@Column(type="integer", columnDefinition="INT(5) UNSIGNED ZEROFILL")
like image 30
loicfavory Avatar answered Oct 10 '22 04:10

loicfavory