Field type tinyint(1) would not save values other than 0 and 1 in CakePHP
Just a quick note. I had a “is_active” field in my users table which i had been using to store boolean 0 and 1 values. Later, i mean today, i decided to save a new value -1 to this field but when i did try, it would’t save -1 and would always save it as 1. After looking at a few blog posts around the web i found that in CakePHP every time you try to save a value other that 0 or 1 into a tinyint(1) field it would save it as 1 (as according to Nate, “Cake interprets MySQL tinyint(1) fields as virtual boolean fields, which can only have a value of 0 or 1 (true or false). Use a different column type if you don’t want this behavior”. You could find related more explanation here https://trac.cakephp.org/ticket/3903 and https://trac.cakephp.org/ticket/1253). So the known best solution so far is that you change the field id to tinyint(2) instead and it should start saving anything between -128 and 127.
Also, another quick note on changing the table structure. Although some folk around there had advised to clear the model cache app/tmp/cache/models) just after manually changing your table structure and before testing the new changes reflect it did work as expected for me even without clearing the cache (may be because i was on debug mode=2). So anyway, if you find sometimes that even after changing the table structure changes would not reflect try clearing model cache in app/tmp/cache/models.
As mentioned at beginning, just a quick note!
. Anyways full credit goes to this post and people there for this quick note of mine
.
Possibly Related posts:
- Multiple validation rules for a single field in cakephp
Cakephp framework provides a strong model validation mechanism. Here is the quick overview of multiple validation rules applied to a single field. Let say we... - Conditional skip for a field from model validation in a cakephp controller
In a controller, a table field could be skipped from model validations by editing the “validate” property of a model. For example, i have a... - Clear template cache in x-cart
Have you been making changing into a smarty template file (within x-cart and perhaps independently as well) for long and the changes would not come... - Cakephp important facts you must know – Part 1
Mininal use of $uses variable to load models CakePHP loads all models specified in var $uses array when a controller action is called. By loading... - Cakephp important facts you must know – Part 3
You load a plugin model like this: $this->loadModel(“Forum.Topic”) You output requestAction result using $this->requestAction(array(‘controller’ => ‘articles’, ‘action’ => ‘featured’), array(‘return’)); // see array(‘return’) In controller,...
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.





