Abstract classes don't work anymore
See original GitHub issueI can’t get extra fields inheriting from an abstract class. Is that feature still available? Example:
from tortoise.models import Model
from tortoise import fields
class AbstractModel(Model):
new_field = fields.CharField(max_length=100)
class Meta:
abstract = True
class ModelOne(AbstractModel):
id = fields.IntField(pk=True)
name = fields.TextField()
After schema initialization we got only id & name fields in ModelOne:
postgres=# \d modelone
Table "public.modelone"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+--------------------------------------
id | integer | | not null | nextval('modelone_id_seq'::regclass)
name | text | | not null |
Indexes:
"modelone_pkey" PRIMARY KEY, btree (id)
There is no new_field
here.
PS: tortoise-orm==0.14.0, asyncpg==0.19.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
java - Why not abstract fields? - Stack Overflow
You can do what you described by having a final field in your abstract class that is initialised in its constructor (untested code):...
Read more >Do we need abstract classes anymore when we have Java 8's ...
For defining variables that are not final we do need abstract classes why because in interfaces by default all variables are static and...
Read more >Abstract Classes
Generally, abstract classes can specify all the standard class components: constructors, methods, and instance variables. Again, a class must be defined with ...
Read more >What is the point of an abstract class? : r/learnprogramming
An abstract class starts to make more sense when you deal with a large codebase and you are working with other devs (at...
Read more >Abstract Classes and Methods - Learn Abstraction in Java
Full Java Course: https://course.alexlorenlee.com/ courses /learn-java-fastGet my favorite programming audiobook for free!
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well done. 👍 Thank you!!
I just released v0.14.2, please test that it resolved the issue for you 😃