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

Bugfixes for abstract tables #1732

Closed mringler closed 3 years ago

mringler commented 3 years ago

I want to mark a table abstract, since it is only used for inheritance:

<table name="person" skipSql="true" abstract="true">...</table>

But the classes built from that schema have errors in them. Marking a table abstract seems to do exactly two things, both cause errors with PHP.

Current behavior 1: The user model class is set to abstract Introduced problem: The query class is still set to instantiate objects from a now abstract class, which is not allowed Proposed solution: If table is abstract, calling methods that usually create instances (findPkSimple()) throw an exception (unless when the table uses concrete_inheritance, which creates instances from other classes).

Current behavior 2: In the table map, set OM_CLASS to empty string and make the function getOMClass() abstract Introduced problem: The table map class is not declared abstract, so it is not allowed to use abstract methods Proposed solution: Instead of making it abstract, let the method throw an exception

On the way, I also did some housecleaning (mostly removal of unused variables).

codecov-commenter commented 3 years ago

Codecov Report

Merging #1732 (3295188) into master (0692734) will increase coverage by 0.00%. The diff coverage is 82.60%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1732   +/-   ##
=========================================
  Coverage     88.32%   88.33%           
- Complexity     7745     7755   +10     
=========================================
  Files           263      263           
  Lines         22232    22259   +27     
=========================================
+ Hits          19637    19663   +26     
- Misses         2595     2596    +1     
Flag Coverage Δ Complexity Δ
5-max 88.33% <82.60%> (+<0.01%) 7755.00 <1.00> (+10.00)
7.4 88.33% <82.60%> (+<0.01%) 7755.00 <1.00> (+10.00)
agnostic 73.67% <65.21%> (+0.01%) 7755.00 <1.00> (+10.00)
mysql 70.40% <82.60%> (-0.09%) 7754.00 <1.00> (+10.00) :arrow_down:
pgsql 70.39% <82.60%> (-0.09%) 7754.00 <1.00> (+10.00) :arrow_down:
sqlite 68.34% <82.60%> (-0.09%) 7754.00 <1.00> (+10.00) :arrow_down:

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

Impacted Files Coverage Δ Complexity Δ
...rc/Propel/Generator/Builder/Om/TableMapBuilder.php 95.05% <0.00%> (-0.56%) 159.00 <0.00> (ø)
src/Propel/Generator/Builder/Om/QueryBuilder.php 91.90% <93.75%> (-0.04%) 160.00 <0.00> (+1.00) :arrow_down:
...pel/Generator/Builder/Om/ExtensionQueryBuilder.php 75.86% <100.00%> (+1.78%) 9.00 <0.00> (ø)
src/Propel/Generator/Model/Table.php 90.92% <100.00%> (+0.53%) 283.00 <1.00> (+1.00)
.../Propel/Generator/Builder/Om/AbstractOMBuilder.php 96.73% <0.00%> (+<0.01%) 159.00% <0.00%> (ø%)
src/Propel/Generator/Schema/Dumper/XmlDumper.php 82.94% <0.00%> (+0.15%) 95.00% <0.00%> (+1.00%)
src/Propel/Generator/Model/Database.php 72.60% <0.00%> (+0.27%) 125.00% <0.00%> (+2.00%)
src/Propel/Generator/Manager/ReverseManager.php 72.22% <0.00%> (+0.39%) 23.00% <0.00%> (ø%)
src/Propel/Generator/Model/ScopedMappingModel.php 95.23% <0.00%> (+0.64%) 28.00% <0.00%> (+5.00%)

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 0692734...3295188. Read the comment docs.

mringler commented 3 years ago

I missed that the query model cannot be abstract, as it might still be instantiated as a filter for the child query objects. That means that findPkSimple() cannot be abstract. Changed it so that it throws an exception.