Skip to content

Bug: Entity casts do not cast the original data #2441

Description

@swearl

Describe the bug

namespace App\Entities;

use CodeIgniter\Entity;

class Item extends Entity {
	protected $attributes = [
		"id" => null,
		"type" => null,
	];

	protected $casts = [
		"type" => "int"
	];
}

eg: I load a data from model, type value is 1, if only use this, no problem

var_dump($item->type); // int(1)

but if i set the value again

$item->type = 1;
var_dump($item->hasChanged()); // true

because the original type value is "1"(string)

CodeIgniter 4 version
rc3

Affected module(s)
CodeIgniter\Entity

Context

  • OS: Windows 10 Pro
  • Web server: Apache/2.4.41 (Win64)
  • PHP version 7.3.12

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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