Skip to content

When is a TINYINT(1) not a TINYINT(1)?

When you’re using CakePHP!

Turns out CakePHP considers a TINYINT(1) to be a Boolean. Judging from all the support tickets that have been filed, I’m not the first person to get taken off guard by this behavior. When I asked about it on IRC, the response was that since MySQL considers a TINYINT(1) to be a Boolean, CakePHP does too. That’s not true.

From the MySQL manual:

As of MySQL 5.0.3, a BIT data type is available for storing bit-field values. (Before 5.0.3, MySQL interprets BIT as TINYINT(1).)

That’s saying if I request a BIT it will make it a TINYINT, not if I request a TINYINT it will make it a BIT. Having a framework change the definitions of my database columns sounds crazy to me, but judging from the ticket filed in 2006 this has been CakePHP’s policy for a long time. Despite the long standing precedent I can’t find any documentation about it online other than the closing remarks of those support tickets.

{ 2 } Comments

  1. George | March 7, 2008 at 7:30 pm | Permalink

    You gotta love that “Automagic”. I never knew about this, so thanks for sharing.

    Personally, I’m beginning to hate cake’s model/ORM. Whatever happened to good old SQL? It’s more of standard then ORM will ever be. The amount of code you write binding and unbinding, you could have written with one SQL statement

  2. Tim Koschuetzki | March 7, 2008 at 9:39 pm | Permalink

    George, which cake version are you using?

    Can you paste your bind and unbind code here please?

Post a Comment

Your email is never published nor shared. Required fields are marked *