0

PHP: 8.1
CakePHP: 4.4.
Postgres: 13

Problem: While generating entity Block, after setting data, the val property is always set to null

Table definition

create table blocks
(
    id         integer generated always as identity
    val        integer[]
);

Im trying to call createNewBlock method (Entity class is completely empty, just extends Cake\ORM\Entity):

class BlocksTable extends Table {
    public function initialize(array $config): void {
        $this->setTable('blocks');
        $this->setEntityClass('App\Model\Entity\Block');
    }

    public function createNewBlock(int ...$val): Block {
        return $this->newEntity([
            'val' => $val
        ]);
    }
}

And the result

App\Model\Entity\Block Object
(
    [val] => 
)

I expected val to be an array but it's always set to null

So i was digging a little bit and dont know why method _buildPropertyMap from Cake\ORM\Marshaller returns columnType = string for column val

Is there any quick fix for that ?

Boorsuk
  • 291
  • 1
  • 10
  • 3
    I don't see arrays listed at [Data Types](https://book.cakephp.org/4/en/orm/database-basics.html#data-types). CakePHP needs to work with different database engines. The PostgreSQL driver is seemingly applying a sane common type and defaulting to text, just like it does with JSON. In that same document you have explanations to build custom types (though someone might have written a plugin). – Álvaro González Apr 21 '23 at 14:42
  • @ÁlvaroGonzález Yea, MB, i should check that. Ty – Boorsuk Apr 24 '23 at 05:48

0 Answers0