I'm not really sure if this is a bug or not, though I think it is:
I have a table in an SQLite DB with (among others) an integer field that is allowed to be null and its default value is also set to null. When I instantiate a model based on that table, the corresponding value is initialized as 0 instead of null. This gives me problems when I use CExistValidator, as blank values are allowed but a value of 0 is checked (and doesn't exist in the primary table), and thus results in a validation error.
This does seem like a bug, since 0 and null are different values. I can't fix this with CDefaultValueValidator since the value isn't '' or null. Before I start hacking with isNewRecord in the model constructor, is there a better way to fix this, either in the model or in the db?
Page 1 of 1
Default values 0 and null in AR
#3
Posted 17 December 2009 - 07:45 AM
i use mysql, no this problem
(yii 1.1 rc)
mysql schema:
controller:
screen print:
(yii 1.1 rc)
mysql schema:
CREATE TABLE yii_user ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(64) NOT NULL, `password` varchar(64) NOT NULL, created int(11) DEFAULT NULL, updated int(11) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
controller:
$user = new User; dump( $user->attributes );
screen print:
array
(
[id] => null
[username] => null
[password] => null
[created] => null
[updated] => null
)
Share this topic:
Page 1 of 1

Help













