Yii Framework Forum: Default values 0 and null in AR - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Default values 0 and null in AR Rate Topic: -----

#1 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 15 December 2009 - 04:22 AM

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?
0

#2 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 17 December 2009 - 06:37 AM

I'd really like some input on this one.
0

#3 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 17 December 2009 - 07:45 AM

i use mysql, no this problem
(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
)

0

#4 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 17 December 2009 - 08:42 AM

Thanks, I'll go file an issue then :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users