diff --git a/composer.json b/composer.json index a25d95d0..c0590dc0 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": ">=8.0", "cycle/orm": "^2.2.0", - "cycle/schema-builder": "^2.2", + "cycle/schema-builder": "^2.3", "doctrine/annotations": "^1.13 || ^2.0", "spiral/attributes": "^2.8|^3.0", "spiral/tokenizer": "^2.8|^3.0", diff --git a/src/Entities.php b/src/Entities.php index 767b29ac..a90ab4a0 100644 --- a/src/Entities.php +++ b/src/Entities.php @@ -81,7 +81,7 @@ public function run(Registry $registry): Registry } foreach ($children as $e) { - $registry->registerChild($registry->getEntity($this->utils->findParent($e->getClass())), $e); + $registry->registerChildWithoutMerge($registry->getEntity($this->utils->findParent($e->getClass())), $e); } return $this->normalizeNames($registry); @@ -157,7 +157,7 @@ private function resolveTarget(Registry $registry, string $name): ?string return $name; } - if (! $registry->hasEntity($name)) { + if (!$registry->hasEntity($name)) { // point all relations to the parent foreach ($registry as $entity) { foreach ($registry->getChildren($entity) as $child) { diff --git a/src/TableInheritance.php b/src/TableInheritance.php index 6cc1cb7d..327d8dfe 100644 --- a/src/TableInheritance.php +++ b/src/TableInheritance.php @@ -133,6 +133,8 @@ private function initInheritance( $parent->getInheritance()->setDiscriminator($annotation->getName()); } + $parent->merge($entity); + return $parent; } if ($inheritance instanceof Inheritance\JoinedTable) { diff --git a/tests/Annotated/Fixtures/Fixtures21/Buyer.php b/tests/Annotated/Fixtures/Fixtures21/Buyer.php new file mode 100644 index 00000000..d66ca281 --- /dev/null +++ b/tests/Annotated/Fixtures/Fixtures21/Buyer.php @@ -0,0 +1,26 @@ +assertTrue(end($indexes)->isUnique()); } - private function compile(ReaderInterface $reader): array + /** + * @dataProvider allReadersProvider + */ + public function testJtiParentColumns(ReaderInterface $reader): void + { + $schema = $this->compile($reader, 'Fixtures21'); + + $this->assertNotEmpty($schema); + + $this->assertArrayHasKey(SchemaInterface::COLUMNS, $schema['person']); + + // assert that parent doesn't have jti columns + $this->assertSame([ + 'id' => 'id', + 'name' => 'name', + 'type' => 'type', + ], $schema['person'][SchemaInterface::COLUMNS]); + } + + private function compile(ReaderInterface $reader, string $fixtures = 'Fixtures16'): array { $tokenizer = new Tokenizer( new TokenizerConfig([ - 'directories' => [__DIR__ . '/../../../../Fixtures/Fixtures16'], + 'directories' => [sprintf(__DIR__ . '/../../../../Fixtures/%s', $fixtures)], 'exclude' => [], ]) );