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

Allow default-value for concrete-inheritance to be instantiable #1771

Closed nederdirk closed 3 years ago

nederdirk commented 3 years ago

We use concrete-inheritance for our 'setting' table[1], and encountered the buggy situation in which we had application crashes on development environments (lots of branch-switching) where a recently-introduced type present in the database would instantiate a nonexisting class.

This patch defaults the behaviour of SettingQuery()->find() to return the base class for unknown types, instead of Package\\Setting, by using the (correctly-namespaced) classname in TableMap::OM_CLASS.

I added a test that verifies that the base class name is returned from TableMap::getOMClass() with an unexpected value.

[1]: example column.

        <column
            name="type"
            type="ENUM"
            required="true"
            default="string"
            valueSet="'string','int','boolean','datetime','country'"
            inheritance="single"
        >
            <inheritance key="string" class="Setting" />
            <inheritance key="int" class="IntegerSetting" extends="Setting" />
            <inheritance key="boolean" class="BooleanSetting" extends="Setting" />
            <inheritance key="datetime" class="DateTimeSetting" extends="Setting" />
            <inheritance key="country" class="CountrySetting" extends="Setting" /><!-- recently introduced -->
        </column>
codecov-commenter commented 3 years ago

Codecov Report

Merging #1771 (a4933fd) into master (1a3140e) will increase coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1771      +/-   ##
============================================
+ Coverage     87.87%   87.89%   +0.01%     
  Complexity     7826     7826              
============================================
  Files           267      267              
  Lines         22543    22544       +1     
============================================
+ Hits          19810    19815       +5     
+ Misses         2733     2729       -4     
Flag Coverage Δ
5-max 87.89% <100.00%> (+0.01%) :arrow_up:
7.4 87.89% <100.00%> (+0.01%) :arrow_up:
agnostic 73.34% <100.00%> (+<0.01%) :arrow_up:
mysql 70.19% <100.00%> (+0.31%) :arrow_up:
pgsql 70.12% <100.00%> (+0.31%) :arrow_up:
sqlite 68.11% <100.00%> (+0.31%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/Propel/Generator/Builder/Om/TableMapBuilder.php 95.06% <100.00%> (+<0.01%) :arrow_up:
src/Propel/Runtime/ActiveQuery/Criteria.php 89.97% <0.00%> (+0.44%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 1a3140e...a4933fd. Read the comment docs.