Skip to content

[Postgre][Entity] cast boolean in entity from PostgreSQL is always true #7483

Open
@shishamo

Description

@shishamo

PHP Version

8.1

CodeIgniter4 Version

4.3.4

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

macOS

Which server did you use?

apache

Database

PostgreSQL 15.2

What happened?

When try to cast boolean value in entity when use PostgreSQL the value is always true

When check the entity the value true is set as string t, and the value false is set as string f

The BooleanCast cast as (bool) $value so the value always returns true

Steps to Reproduce

class TestEntity extends BaseEntity
{
    protected $casts = [
        'bolean_value'  => 'boolean',
    ];
    protected $datamap = [
        'boleanValue' => 'bolean_value',
    ];
}
class TestModel extends APIBaseModel
{
    protected $table = 'postgresql_table';
    protected $returnType = TestEntity::class;
}
class TestController extends BaseController
{
    protected $modelName = TestModel::class;

    public function find(): Response
    {
        return $this->respond($this->model->first());
    }
}

Expected Output

{
    "boleanValue": false
}

When postgresql DB entry is false but always returns true

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementPRs that improve existing functionalities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions