Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/Entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/TableInheritance.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ private function initInheritance(
$parent->getInheritance()->setDiscriminator($annotation->getName());
}

$parent->merge($entity);

return $parent;
}
if ($inheritance instanceof Inheritance\JoinedTable) {
Expand Down
26 changes: 26 additions & 0 deletions tests/Annotated/Fixtures/Fixtures21/Buyer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures21;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Inheritance\JoinedTable;

/**
* @Entity
* @JoinedTable
*/
#[Entity]
#[JoinedTable]
class Buyer extends Person
{
/** @Column(type="string") */
#[Column(type: 'string')]
public string $foo;

/** @Column(type="string") */
#[Column(type: 'string')]
public string $bar;
}
22 changes: 22 additions & 0 deletions tests/Annotated/Fixtures/Fixtures21/Employee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures21;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Inheritance\JoinedTable;

/**
* @Entity
* @JoinedTable
*/
#[Entity]
#[JoinedTable]
class Employee extends Person
{
/** @Column(type="integer") */
#[Column(type: 'integer')]
public int $salary;
}
22 changes: 22 additions & 0 deletions tests/Annotated/Fixtures/Fixtures21/Executive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures21;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Inheritance\JoinedTable;

/**
* @Entity
* @JoinedTable
*/
#[Entity]
#[JoinedTable]
class Executive extends Employee
{
/** @Column(type="integer") */
#[Column(type: 'integer')]
public int $bonus;
}
27 changes: 27 additions & 0 deletions tests/Annotated/Fixtures/Fixtures21/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Cycle\Annotated\Tests\Fixtures\Fixtures21;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;

/**
* @Entity
*/
#[Entity]
class Person
{
/** @Column(type="primary") */
#[Column(type: 'primary')]
protected int $id;

/** @Column(type="string") */
#[Column(type: 'string')]
public string $name;

/** @Column(type="string") */
#[Column(type: 'string')]
public string $type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Cycle\Database\Schema\AbstractIndex;
use Cycle\ORM\EntityManager;
use Cycle\ORM\Schema;
use Cycle\ORM\SchemaInterface;
use Cycle\Schema\Compiler;
use Cycle\Schema\Generator\GenerateRelations;
use Cycle\Schema\Generator\GenerateTypecast;
Expand Down Expand Up @@ -192,11 +193,30 @@ public function testAddIndex(ReaderInterface $reader): void
$this->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' => [],
])
);
Expand Down