1
votes

I have a column with type "simple_array" in my schema definition:

public function up(Schema $schema)
{
    $users = $schema->createTable('users');
    $users->addColumn('id', 'integer', ['unsigned' => true,
       'autoincrement' => true]);
    $users->addColumn('email', 'string', ['length' => 100]);
    $users->addColumn('roles', 'simple_array');
    $users->setPrimaryKey(['id']);
}

With that code above, I was able to generate a table like this:

enter image description here

Now, somewhere in my code, I inserted a record for that users table:

$connection->insert('users', ['email' => '[email protected]', 'roles' => ['admin', 'editor']]);

I was able to successfully execute that insertion call. But the thing is that the roles column is not stored as the doctrine's documentation promised - see simple_array in Doctrine Types. Here is how it is actually stored on my part:

enter image description here

I traced the core codebase of Doctrine and I can't really find any hint of transformer codes to transform that "simple_array" type to a comma-imploded string.

I worked with Doctrine ORM before and this was working fine. Is this something that the Doctrine ORM implemented and not by the Doctrine DBAL itself? If so, how should this be done in DBAL? manually?

Thanks.

1

1 Answers

0
votes

I think it is located at: dbal\lib\Doctrine\DBAL\Types\SimpleArrayType.php line 45-57, functions convertToDatabaseValue and convertToPHPValue.

Maybe because you are using low-level functions(DBAL), it does not trigger automatically. (So you may need to add 3rd parameter here) $connection->insert('users', ['email' => '[email protected]', 'roles' => ['admin', 'editor']], ['email' => Type::STRING, 'roles' => Type::SIMPLE_ARRAY]);