Repository navigation
feat: add support for model inheritance - #16095
Merged
Merged
Conversation
ephys
marked this pull request as draft
June 3, 2023 13:26
ephys
marked this pull request as ready for review
June 3, 2023 14:24
WikiRik
reviewed
Jun 5, 2023
WikiRik
left a comment
Member
There was a problem hiding this comment.
One compliment and one small question, but apart from that it looks great!
WikiRik
approved these changes
Jun 17, 2023
ephys
enabled auto-merge (squash)
June 17, 2023 13:49
auto-merge was automatically disabled
June 17, 2023 14:21
Merge queue setting changed
ephys
enabled auto-merge
June 17, 2023 14:22
ephys
added this pull request to the merge queue
Jun 17, 2023
This was referenced Jun 17, 2023
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.
Pull Request Checklist
Description Of Change
This PR makes extending a model inherit the relevant model options, attributes, and associatiosn
This feature is only available for the new decorator-based model declaration.
Abstract Models
the
@Table.Abstractdecorator can be used to declare abstract models that can only be used for inheritance.These models are never initialized. They only exist to register metadata on them.
Model Option Inheritance
Options are inherited from parent models just like if you used the
@Tabledecorator multiple times on the final model. In case of conflicting options, the options set on the descendant overwrite the options set on the parent instead of throwing an error.The
tableName,nameandmodelNameoptions are never inherited.Attribute Inheritance
Options are inherited from parent models just like if you used the
@Attributedecorator multiple times on the final model. In case of conflicting options, the options set on the descendant overwrite the options set on the parent instead of throwing an error.Association Inheritance
Only
@BelongsTowithout theinverseoption can be inherited. All other association types, or using theinverseoption will throw an error.This limitation is put into place to prevent associations from declare conflicting associations on the target model.
This could be revisited in the future by providing a way to apply different options based on which child model is being initialized, like this:
But that is currently out of scope.
Todos