Repository navigation
set class key on single table inheritance base class - #180
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Single table inheritance allows to define a class key for the main 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
constwith 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.