Skip to content
Advertisement

Add TINYINT to Doctrine SQL types

Following Symfony doc, I tried to add TINYINT as entity column type.

So far it works well, but two problem remain…

  1. Each time I want to perform a migration, Doctrine can’t reconize TINYINT for the associated columns, and perform the migration queries again.

  2. In form builders, by default TINYINT is reconized as TextType and not NumberType

Do you know what I’m missing to fix those two issues?

TinyintType.php

JavaScript

doctrine.yaml

JavaScript

Advertisement

Answer

First issue: From https://blog.vandenbrand.org/2015/06/25/creating-a-custom-doctrine-dbal-type-the-right-way/

The solution is to add a comment to the field to store the metadata in. This seems to be missing in the docs but I’ve found some JIRA issue describing the feature. We have to change our column definition so the metadata of the type doesn’t get lost

So your getSQLDeclaration should be like this:

JavaScript

Second issue: That’s because, by default symfony forms uses text type (symfony/form/FormBuilder.php::create)

JavaScript

You should set your type explicitly if you want set another type.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement