-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Postgre][Entity] cast boolean in entity from PostgreSQL is always true #7483
Comments
@kenjis is there any update to that issue? |
No. I think this is not a bug. The current implementation does not support PostgreSQL bool type. |
You can extend the BooleanCast class and cast the type you need. @kenjis Entity is a representation of data and is not directly related to the DBMS. I don't think this is a good solution. |
@iRedds What do you mean? You think adding |
<?php
namespace App\Entities\Cast;
use CodeIgniter\Entity\Cast\BooleanCast as BaseCast;
class BooleanCast extends BaseCast
{
public static function get($value, array $params = []): bool
{
if ($value === 't') {
return true;
}
if ($value === 'f') {
return false;
}
return parent::get($value, $params);
}
} Actually this is what i have done in my own extended cast. But i was wondering why it is not handled by CI by default because the Postgre driver exists |
@kenjis I think it should be left as is. |
@iRedds CI4 supports PostgreSQL but the Entity cannot support boolean type column. |
@kenjis But Entity is not part of the database layer. And the desired result can be obtained through a getter or custom type casting. |
#8243 would solve this issue. |
Thank you @kenjis ~ |
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 stringt
, and the valuefalse
is set as stringf
The
BooleanCast
cast as(bool) $value
so the value always returnstrue
Steps to Reproduce
Expected Output
When postgresql DB entry is
false
but always returnstrue
Anything else?
No response
The text was updated successfully, but these errors were encountered: