Skip to content

Bug: builder replace() not setting created_at as expected. #9692

@mavelo-llc

Description

@mavelo-llc

PHP Version

8.2

CodeIgniter4 Version

4.6.3

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

10.4.32-MariaDB

What happened?

Calling builder's replace() method sets updated_at to current time but sets created_at to '0000-00-00 00:00:00'

Closest issue found was #5229 (closed)

Table structure

CREATE TABLE `translation` (
  `translation_id` int(10) UNSIGNED NOT NULL,
  `language_id` int(10) UNSIGNED NOT NULL,
  `table` varchar(255) NOT NULL,
  `row` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `value` text NOT NULL,
  `created_at` datetime NOT NULL,
  `updated_at` datetime DEFAULT NULL,
  `deleted_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

ALTER TABLE `translation`
  ADD PRIMARY KEY (`translation_id`),
  ADD KEY `list` (`language_id`,`table`,`row`,`name`) USING BTREE,
  ADD KEY `edit` (`table`,`row`,`name`) USING BTREE,
  ADD KEY `delete` (`table`,`row`) USING BTREE,
  ADD KEY `sort` (`value`(16)) USING BTREE;

ALTER TABLE `translation`
  MODIFY `translation_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=19;
COMMIT;

Steps to Reproduce

Relevant portion of our model

<?php

namespace App\Models;

class UserGroupModel extends BaseModel {
	protected function afterSave(array $data): void {
		if ($data['result']) {
			foreach (request()->getPost('names') as $language_id => $name) {
				model('TranslationModel')->replace([
					'language_id' => $language_id,
					'table' => $this->table,
					'row' => $data['id'],
					'name' => 'name',
					'value' => $name,
				]);
			}
		}
	}
}

Row export from phpMyAdmin

INSERT INTO `translation` (`translation_id`, `language_id`, `table`, `row`, `name`, `value`, `created_at`, `updated_at`, `deleted_at`) VALUES
(18, 2, 'user_group', '25', 'name', 'El Test', '0000-00-00 00:00:00', '2025-08-26 19:34:21', NULL);

Expected Output

Expected created_at to match updated_at

INSERT INTO `translation` (`translation_id`, `language_id`, `table`, `row`, `name`, `value`, `created_at`, `updated_at`, `deleted_at`) VALUES
(18, 2, 'user_group', '25', 'name', 'El Test', '2025-08-26 19:34:21', '2025-08-26 19:34:21', NULL);

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions