We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Is there an easy way to tell phalcon to distinguish TINYINT(1) from INT(*)?

Hello, I've been using TINYINT(1) as boolean for a while now. I came across a problem when I tried to use models metadata to automate resultset representation. That's what I'm trying to achieve:

{%- for key, fieldName in columnNames -%}
        <td>
          {% if columnTypes[fieldName] === constant("Phalcon\Db\Column::TYPE_DATETIME") %}
            {{date('d.m.Y h:i',strtotime(row.readAttribute(fieldName)))}}
         /* I need some way to distinguish TINYINT type of column to view it appropriately
          {% elseif columnTypes[fieldName] === constant("Phalcon\Db\Column::TYPE_TINYINT") %}
          put some graphics for 'yes' 'no' value like 'V' 'X'
          */
          {% else %}            
            {{ row.readAttribute(fieldName) }}
          {% endif %}
        </td>
{%- endfor -%}

I understand that Phalcon cast all mysql ?INT() datatypes to integer (because php have only integer). And I understand that I can manually set all metadata for my models but I have a lot of them. And I don't want to redefine mysql columns also(e.g. change TINYINT() for BOOLEAN/BYTE) because tinyint is more consistent. Is there any way to tell phalcon just about few tinyint columns without defining a bunch of metadatas manyally?

Hi Jaysjay the fast and simple way change all booleans columns in your schema to bit and then use \Phalcon\Db\Column::TYPE_BOOLEAN to indentify them

On the other hand create your own Model extending \Phalcon\Mvc\Model adding all functionality to work with tinyint

Personally take the first path a long time ago