Skip to content

find() is returning one character string instead of boolean #2096

Description

@hlohrenz

Describe the bug
I have a postgres database and after I insert a record using CI's query builder, I see that the boolean field can_be_sold is indeed inserting as a boolean. However after I perform a find() on this record, it's returning a string as "t" instead of true. My ItemModel looks like this:

<?php namespace Item\Models;

use App\Models\BaseModel as Model;

class Item extends Model
{
    protected $table      = 'items';
    protected $primaryKey = 'id';
    protected $returnType = '\Item\Models\Item';

    protected $allowedFields = ['name', 'description', 'image_path', 'can_be_sold', 'rarity'];

    protected $useSoftDeletes = true;
    protected $useTimestamps  = true;
    protected $skipValidation = true;
}

My BaseModel looks like this:

<?php namespace App\Models;

use CodeIgniter\Model;

class BaseModel extends Model implements \JsonSerializable
{
    /**
     * Fields to hide when being serialized.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * Populate model with array of data.
     *
     * @param array $data
     * @return Model
     */
    public function populateFromArray(array $data)
    {
        $classSet = \Closure::bind(function ($key, $value) {
            $this->$key = $value;
        }, $this, get_class($this));
        foreach (array_keys($data) as $key)
        {
            $classSet($key, $data[$key]);
        }
        return $this;
    }

    public function toArray()
    {
        return (array) $this;
    }

    /**
     * How object returns when being serialized.
     *
     * @return array|mixed
     */
    public function jsonSerialize()
    {
        foreach ($this->hidden as $field)
        {
            unset($this->$field);
        }

        return $this;
    }
}

CodeIgniter 4 version
"codeigniter4/framework": "4.0.0-beta.2"

Affected module(s)
CodeIgniter\Model

Expected behavior, and steps to reproduce if appropriate
It should return boolean as it is pulled from the database. I am looking at the record and it is boolean datatype and is states true.

Context

  • OS: Mac
  • Web server Apache
  • PHP version 7.2

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions