4 ms·
What's wrong with Django's orm? Does it have something particularly bad compared to others?
by riffraff 3y ago
What's wrong with Django's orm?
Does it have something particularly bad compared to others?
- cdcarter 3y agoI think the poster is specifically referring to using inheritance in Django ORM, where if you had e.g. a model Book and then a model Novel that inherits from it. In python these are modeled as a class inheritance hierarchy, and Django (at least, by default) creates a database table per class in the hierarchy. If you have 3-4 levels of inheritance, that's 3-4 extra joins per query.
- mixmastamyk 3y agoWe use that, a base model and some mixins, but we use Meta.abstract=True (or similar, not at my desk) on the parents and have not noticed any issues, though have not looked for them either! Should I be concerned?
- cdcarter 3y agoThat works fine. It's when you inherit from a non-abstract model that you end up with the trickier data model.
- pmontra 3y agoThis. That customer of mine started a project a few years before hiring me. They used inheritance and each model is scattered around a number of tables. No external tool can sensibly access that database, except that very Django app and its manage.py commands. Add a similarly enthusiastic use of apps under the same main directory and the database is a mess of long named tables with a tangle of relationships between them. We started another project later on and we planned the database first. We wrote one model per table, no inheritance, only a few cleanly delimited apps. We still use makemigrations and migrate but if we want we can write a piece of software on any language to access that database.
- riffraff 3y agoOh, got it thanks