Repository navigation
feat: inheritance for DB class - #2799
Merged
Merged
Conversation
removes `mutuallyExclusiveKeys` from both `table` and `extends` removes the restriction disallowing a parentClass from having a table added the restriction disallowing 2 table-classes in the same hierarchy inheritance_test.dart was updated: - removes tests checking for mutuallyExclusiveKeys between table and extends - adds test checking restriction that only one table in hierarchy is allowed inheritance_class_test.dart - adds test checking if child-class TableClass inherits all fields of parent
adds comments to ClassDefinition getters and adds another getter for `allFields` merging fields and parentFields together and keeps the id field first passes allFields to `createDatabaseDefinitionFromModels` model_library_generator.dart: - refactors the way fields is used, setting fields equal to allFields and only using `fields` and `parentFields` when they need to be distinguished - adds a ternary statement changing the type of 'id' to be `Object?` in _buildAbstractCopyWithParameters
Seems like I wrote `validateExtendingClassName` right inbetween `validateTableNameKey` and `validateTableName` meaning they were ordered as - validateTableNameKey - validateExtendingClassName -validateTableName and now - validateTableNameKey -validateTableName - validateExtendingClassName
SandPod
requested changes
Oct 4, 2024
SandPod
left a comment
Contributor
There was a problem hiding this comment.
Nice work! 🌟
Getting closer!
I have a couple of comments and suggestions.
But I would also like to see some e2e tests that validate we can define models with the different hierarchies.
Say for example 3 tests where the table is defined in all different places in this hierarchy:
Grandparent -> Parent -> Child.
This would help us validate that the migrations are generated correctly.
changes ParentClass to have a table renames fields adds GrandParentClass adds test checking if child can be inserted in parent-table squashes new migration with previous migration
…ngInherited` from parent rename: - parentFields => inheritedFields - allFields => fieldsIncludingInherited also in inheritedFields now `fieldsIncludingInherited` are passed to accomodate multi level inheritance
rename private variable remove cast and add guard checking if currentModel is ClassDefnition improve wording of Exception thrown when multiple classes have inheritance improve wording of test description
SandPod
reviewed
Oct 7, 2024
SandPod
left a comment
Contributor
There was a problem hiding this comment.
Nice work, last couple of comments and suggestions!
…o instance of child
…arent-class in test description
SandPod
reviewed
Oct 7, 2024
SandPod
approved these changes
Oct 7, 2024
SandPod
left a comment
Contributor
There was a problem hiding this comment.
LGTM!
Once last thing to fix.
…dart Co-authored-by: Alexander Sandor <[email protected]>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR adds the functionality allowing a class with DB Table to be extended aswell.
Changes:
DB classesDB classesin the same hierarchyfields/inheritedFields/fieldsIncludingInheritedis derived by adding a getter toClassDefinitionthis includes a refactor ofmodel_library_generator.dartfieldsIncludingInheritedinstead offieldstocreateDatabaseDefinitionFromModelsrelated to: #1873 and #1618
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
No breaking changes