zf2 doctrine2 how to use tinyint datatype in entity column
Imo you should just use the column type bool Doctrine then will convert this into tinyint in mysql for you.
/**
* @var bool
* @ORM\Column(type="boolean")
*
* @Form\Exclude()
*/
protected $isActive;
You could also define a default value like so:
...
protected $isActive = true;
...
But rather then doing that you should set in in your populate.
Use columnDefinition, though it is not an ideal solution but serve the purpose.
/**
*
* @ORM\Column(columnDefinition="TINYINT DEFAULT 1 NOT NULL")
*/
protected $isActive;
columnDefinition: DDL SQL snippet that starts after the column name and specifies the complete (non-portable!) column definition. This attribute allows to make use of advanced RMDBS features. However you should make careful use of this feature and the consequences. SchemaTool will not detect changes on the column correctly anymore if you use “columnDefinition”.
Additionally you should remember that the “type” attribute still handles the conversion between PHP and Database values. If you use this attribute on a column that is used for joins between tables you should also take a look at @JoinColumn.
There is no tinyint
type in Doctrine 2. Reason is straightforward:
A Doctrine type defines the conversion between PHP and SQL types, independent from the database vendor you are using. All Mapping Types that ship with Doctrine are fully portable between the supported database systems.
You should pick one of these:
integer
: Type that maps a SQL INT to a PHP integer.smallint
: Type that maps a database SMALLINT to a PHP integer.bigint
: Type that maps a database BIGINT to a PHP string.
Official docs here: http://docs.doctrine-project.org/en/latest/reference/basic-mapping.html#doctrine-mapping-types