CakePHP 2:

Not noticed this behaviour before, is it by design? (Seems odd if it is...)

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(32) NOT NULL,
  `password` varchar(64) NOT NULL,
  `is_active` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  KEY `is_active` (`is_active`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

(Notice in particular the NOT NULL flags on username & password:


class User extends AppModel {

    public function activate($id) {

        $this->User->id = $id;
        $this->User->saveField('is_active', 1);

    }

}

With an empty table:

$this->User->activate(1);

Creates a new user with an id of 1, an empty string for username and 
password, and is_active = 1;

I expected this to fail as User.id 1 doesn't exist.

$this->User->activate(99);

Creates a new user with an id of 2, an empty string for username and 
password, and is_active = 1;

I expected this to fail as User.id 99 doesn't exist.
Even if I disregard that user 99 doesn't exist, I'd expect the new record 
to be created with an id of 99 (not 2)

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to