CakePHP and tinyint as logical

How to make CakePHP 2.x retrieve a tinyint database column not like boolean, but like tinyint?

MySQL:

Column | type ------------------------------- ... | ... category_id | tinyint(1) ... | ... 

CakePHP:

 $this->request->data = $this->Question->read(); var_dump($this->request->data['Question']['category']); 

The value is always 0 (if the question I choose as the category identifier is 0) or 1 (if the question has any other category identifier).

+6
source share
2 answers

Use TINYINT(2) instead. If the length is 1, then Cake sees it as a logical one.

+15
source

The correct way (CakePHP3) if anyone else has this problem

Model \ UsersTable.php

 protected function _initializeSchema( Schema $schema) { //this is a bigInt(20) field (other same type known Cakephp problem) $schema->columnType('OtherField' , 'string'); //this is a tinyint field $schema->columnType('Type' , 'integer'); return $schema; } 
0
source

Source: https://habr.com/ru/post/916920/


All Articles