Question

I'm upgrading a system from CakePHP 1.1 to 1.3. When using create() (followed by save()) in 1.1 the system would happily add an insert an entry to the database with the created and modified datetime fields set to that of the time it was created. However, in 1.3 this is no longer correctly happening. Here the modified is still set to the current time upon the creation and save, but the created datetime is not being set. Any suggestions as to why this might be occurring? Thanks!

Create Table Code (as requested in comment):

CREATE TABLE `units` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `id_b36` VARCHAR(4) NULL DEFAULT NULL,
    `subject_id` INT(10) UNSIGNED NOT NULL,
    `gradelevel_id` INT(10) UNSIGNED NOT NULL,
    `user_id` INT(10) UNSIGNED NOT NULL,
    `school_id` INT(10) NULL DEFAULT NULL,
    `district_id` INT(10) NULL DEFAULT NULL,
    `description` VARCHAR(255) NOT NULL,
    `sort` FLOAT(5,1) NOT NULL DEFAULT '0.0',
    `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
    PRIMARY KEY (`id`),
    INDEX `subject_id` (`subject_id`),
    INDEX `gradelevel_id` (`gradelevel_id`),
    INDEX `sort` (`sort`),
    INDEX `school_id` (`school_id`, `district_id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
ROW_FORMAT=DEFAULT
AUTO_INCREMENT=483

I should note that this is just one of the tables, the same thing occurs on all other models. Thanks!

Était-ce utile?

La solution

created DEFAULT NULL

CakePHP will only populate created if it is defined as NULL:

By defining a created and/or modified field in your database table as datetime fields (default null), CakePHP will recognize those fields and populate them automatically whenever a record is created ...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top