annotated icon indicating copy to clipboard operation
annotated copied to clipboard

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

Open peldax opened this issue 1 year ago • 0 comments

No duplicates 🥲.

  • [X] I have searched for a similar issue in our bug tracker and didn't find any solutions.

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

  • OS: PopOS
  • PHP version: 8.3.7
  • Package version:
    • annotated: 4.1
    • database: 2.11
    • orm: 2.8
    • schema-builder: 2.8

ORM Schema

No response

peldax avatar Jun 21 '24 11:06 peldax