-
-
Notifications
You must be signed in to change notification settings - Fork 84
Closed
Labels
status:ready for adoptionFeel free to implement this issue.Feel free to implement this issue.type:bugBugBug
Description
What happened?
Preparation:
composer require cycle/orm
Simple script for reproduce problem:
<?php
declare(strict_types=1);
include 'vendor/autoload.php';
use Cycle\Database;
use Cycle\Database\Config;
use Cycle\ORM;
use Cycle\Schema;
$dbal = new Database\DatabaseManager(
new Config\DatabaseConfig([
'default' => 'default',
'databases' => [
'default' => ['connection' => 'sqlite']
],
'connections' => [
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\FileConnectionConfig(__DIR__ . '/test.db'),
),
]
])
);
$dbal->database()->execute('DROP TABLE IF EXISTS users');
$registry = new Schema\Registry($dbal);
$entity = new Schema\Definition\Entity();
$entity
->setRole('user')
->setClass(User::class);
$entity->getFields()
// uncomment next line and run script again
// ->set('text', (new Schema\Definition\Field())->setType('string')->setColumn('text'))
->set('id', (new Schema\Definition\Field())->setType('primary')->setColumn('id')->setPrimary(true));
$registry->register($entity);
$registry->linkTable($entity, 'default', 'users');
$schema = (new Schema\Compiler())->compile($registry, [
new Schema\Generator\RenderTables(),
new Schema\Generator\SyncTables(),
]);
$orm = new ORM\ORM(new ORM\Factory($dbal), new ORM\Schema($schema));
$em = new ORM\EntityManager($orm);
$em->persist(new User('1'))->run();
echo 'ROWS COUNT: ' . count($dbal->database('default')->query('SELECT * FROM users')->fetchAll());
class User
{
public function __construct(
public string $text = '',
) {
}
}Run script:
ROWS COUNT: 0
Enable 'text' mapping in entity (uncomment ->set() line) and run script again:
ROWS COUNT: 1
Version
ORM 2.0.0
PHP 8.1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
status:ready for adoptionFeel free to implement this issue.Feel free to implement this issue.type:bugBugBug
Type
Projects
Status
Released