2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

cakePHPでtinyint型を扱うときの注意事項

Posted at

cakePHPではMySQLのtinyint型をboolean型として扱ってしまいます。

cakePHPではtinyintを使うな!という意見もありますが、以下のようにvirtualFieldsで型変換することにより、tinyintを「0」「1」以外で使うことができます。

以下をModel内で定義する。以下はstatusカラム(tinyint型)の例。

    public $virtualFields = array(
        'status' => 'CAST(モデル名.status as CHAR)',
    )
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?