diff --git a/system/Model.php b/system/Model.php index b18deccd77af..4fe4eef2ef0f 100644 --- a/system/Model.php +++ b/system/Model.php @@ -898,15 +898,15 @@ public function updateBatch(array $set = null, string $index = null, int $batchS * Deletes a single record from $this->table where $id matches * the table's primaryKey * - * @param integer|array|null $id The rows primary key(s) - * @param boolean $purge Allows overriding the soft deletes setting. + * @param integer|string|array|null $id The rows primary key(s) + * @param boolean $purge Allows overriding the soft deletes setting. * * @return mixed * @throws \CodeIgniter\Database\Exceptions\DatabaseException */ public function delete($id = null, bool $purge = false) { - if (! empty($id) && is_numeric($id)) + if (! empty($id) && (is_numeric($id) || is_string($id))) { $id = [$id]; } diff --git a/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php b/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php index f0f7eea2c837..a2d294ead8ab 100644 --- a/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php +++ b/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php @@ -130,6 +130,17 @@ public function up() ]); $this->forge->addKey('id', true); $this->forge->createTable('secondary', true); + + // Stringify Primary key Table + $this->forge->addField([ + 'id' => [ + 'type' => 'VARCHAR', + 'constraint' => 3, + ], + 'value' => ['type' => 'TEXT'], + ]); + $this->forge->addKey('id', true); + $this->forge->createTable('stringifypkey', true); } //-------------------------------------------------------------------- @@ -141,6 +152,7 @@ public function down() $this->forge->dropTable('misc', true); $this->forge->dropTable('empty', true); $this->forge->dropTable('secondary', true); + $this->forge->dropTable('stringifypkey', true); } //-------------------------------------------------------------------- diff --git a/tests/_support/Database/Seeds/CITestSeeder.php b/tests/_support/Database/Seeds/CITestSeeder.php index 02dde787e7c3..bd85c0c35614 100644 --- a/tests/_support/Database/Seeds/CITestSeeder.php +++ b/tests/_support/Database/Seeds/CITestSeeder.php @@ -6,7 +6,7 @@ public function run() { // Job Data $data = [ - 'user' => [ + 'user' => [ [ 'name' => 'Derek Jones', 'email' => 'derek@world.com', @@ -28,7 +28,7 @@ public function run() 'country' => 'UK', ], ], - 'job' => [ + 'job' => [ [ 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored', @@ -46,7 +46,7 @@ public function run() 'description' => 'Only Coldplay can actually called Musician', ], ], - 'misc' => [ + 'misc' => [ [ 'key' => '\\xxxfoo456', 'value' => 'Entry with \\xxx', @@ -60,6 +60,12 @@ public function run() 'value' => ' One two three tab', ], ], + 'stringifypkey' => [ + [ + 'id' => 'A01', + 'value' => 'test', + ], + ], ]; foreach ($data as $table => $dummy_data) diff --git a/tests/_support/Models/StringifyPkeyModel.php b/tests/_support/Models/StringifyPkeyModel.php new file mode 100644 index 000000000000..bf15414d8a21 --- /dev/null +++ b/tests/_support/Models/StringifyPkeyModel.php @@ -0,0 +1,9 @@ +seeInDatabase('stringifypkey', ['value' => 'test']); + + $model->delete('A01'); + + $this->dontSeeInDatabase('stringifypkey', ['value' => 'test']); + } + + //-------------------------------------------------------------------- + public function testDeleteWithSoftDeletes() { $model = new UserModel();