propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 399 forks source link

Code quality: Fix single table inheritance classkey type #1982

Closed mringler closed 4 months ago

mringler commented 1 year ago

When using single table inheritance, the keys for the individual classes are written to the TableMap as constants. Those are used during instantiation of the subclasses.

For example, an inheritance declaration like

        <column name="type_indicator"  inheritance="single">
            <inheritance key="firstClassIdentifier" class="..." extends="..."/>
        </column>

will create a constant in the TableMap:

    public const CLASSKEY_FIRSTCLASSIDENTIFIER = 'firstClassIdentifier';

and a constructor of the subclass:

    public function __construct()
    {
        parent::__construct();
        $this->setTypeIndicator(FooTableMap::CLASSKEY_FIRSTCLASSIDENTIFIER);
    }

The value of the classkey constant is always written as a string, even for numeric values:

    public const CLASSKEY_1 = '1';'

This leads to a type error in the generated constructor code, since the setter function for the numeric field will expect a numeric value.

With the changes in this PR, numeric class key constants are written as numeric values, fixing the type error.

Includes the test fix from #1980.