Skip to content

set class key on single table inheritance base class - #180

Merged
mringler merged 1 commit into
perplorm:mainfrom
mringler:inheritance-base
Nov 12, 2026
Merged

mringler merged 1 commit into
perplorm:mainfrom
mringler:inheritance-base

Conversation

@mringler

Copy link
Copy Markdown
Collaborator

Issue

Single table inheritance allows to define a class key for the main table:

        <table name="main">
            <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true"/>
            <column name="type" type="INTEGER" required="true" inheritance="single">
                <inheritance key="44" class="Main"/>
                <inheritance key="23" class="Child1" extends="Main"/>
            </column>
        </table>

However, the main table model classes are generated as usual, so the requested class key will not be set.

Changes

The base object builder now checks if it builds for single table inheritance with a requested class key. If so, it adds a setter call to the generated constructor code.

Implementation Details

I would prefer if the child classes only set a const with their respective class key value, and the base model constructor handles setting the field using the (overridden) const, but that is more than I want to change right now.

Test strategy

Create class and check if value matches.

Notes

The change affects existing tables, where despite the declaration, main table class key remained null. Upon read, these will now be set to the requested value, and updated on next save. While this should not have any impact on functionality, it leads to inconsistencies, where some rows have a null value while other have a class key, even though they build the same model class.
This can be easily fixed with a manual update.

@mringler mringler added the bug Something isn't working label Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mringler
mringler merged commit 01d05ec into perplorm:main Nov 12, 2026
42 checks passed
@mringler
mringler deleted the inheritance-base branch November 12, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant