cycle / annotated

Schema generation using annotated entities and mappers
MIT License
23 stars 12 forks source link

[Bug]: Columns declared in non-entity classes are ignored 🐛 #101

Open peldax opened 2 weeks ago

peldax commented 2 weeks ago

No duplicates 🥲.

What happened?

Hi,

In a scenario where some sort of BaseEntity is used to contain Columns appearing across multiple Entitys, those columns are not registered into the Entitys extending this base class.

abstract class EmployedPerson
{
    #[Column(type: 'integer')]
    protected int $id;
}

#[Entity]
class Developer extends EmployedPerson {
    #[Column(type: 'integer')]
    protected int $salary;
}

In the example above, the id column is not added to the Developer entity.

This is probably caused by Configurator:115:

$field->setEntityClass($property->getDeclaringClass()->getName());

where the field is set to entity by a declaring class, but this class is not an entity.

This should work also in combination with JTI, where a following hierarchy could be used:

#[Entity]
class Person {
    #[Column(type: 'primary')]
    protected int $id;
}

abstract class EmployedPerson extends Person
{
    #[Column(type: 'integer')]
    protected int $salary;
}

#[Entity]
#[JoinedTable]
class Developer extends EmployedPerson {
    #[Column(type: 'integer')]
    protected int $foo;
}

In the example above, the Developer table should contain columns id, salary and foo, but currently the salary is ignored.

Version

ORM Schema

No response