Skip to content

[Bug]: Second-level STI child gets its own table #143

Open

Description

@roxblnfk

Describe the bug

A second-level STI child gets its own table. With Ceo → Employee → Person, where Person declares #[SingleTable], Ceo is linked to a ceos table instead of people, and SyncTables creates an empty ceos table.

TableInheritance::getTableName() and getDatabase() take the immediate parent ($this->utils->getParent($childClass, false)) and check whether its inheritance is SingleTableInheritanceSchema. For Ceo the immediate parent is Employee, which is itself an STI child and has no inheritance schema of its own, so the method falls back to the child's own table and database instead of walking up to the STI root.

Is this a regression?

Not checked.

To Reproduce

  1. Use the Fixtures16 entities from the test suite: Person (#[SingleTable]), Employee extends Person, Ceo extends Employee.
  2. Compile the schema with TableInheritance and SyncTables.
  3. Ceo's schema points at table ceos, and an empty ceos table is created.

Expected behaviour

Every class in an STI hierarchy uses the root's table and database, whatever its depth.

Media prove

Not applicable.

Database

All of them (schema compilation, before any SQL).

Your environment

cycle/annotated 4.x, src/TableInheritance.php (getTableName(), getDatabase()).

Additional context

Found while killing escaped mutants in #142: the mutants on lines 306 and 325 of TableInheritance.php survive because no test covers a second-level STI child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions