0

Doctrine2: CHAR with annotations

Posted November 7th, 2012 in Razno and tagged , , by Metod

Ever wondered if there is a better way of defining a CHAR (mysql) with doctrine2 annotations?

From doctrine2 docs:

  1. <?php
  2. /**
  3.  * @Column(type="string", columnDefinition="CHAR(2) NOT NULL")
  4.  */
  5. protected $country;

Not a very nice approach imo. I dug around the code and found a somewhat neater solution:

  1. <?php
  2. /**
  3.  * @Column(type="string", length=2, options={"fixed" = true})
  4.  */
  5. protected $country;

Now you don’t need to manually type in column definitions. Enjoy!