Introduce inheritance
Pre-release
Pre-release
Breaking
- Breaking:
remove()parent from child side in reverse ForeignKey relation now requires passing a relationname,
as the same model can be registered multiple times andormarneeds to know from which relation on the parent you want to remove the child. - Breaking: applying
limitandoffsetwithselect_relatedis by default applied only on the main table before the join -> meaning that not the total
number of rows is limited but just number of main models (first one in the query, the one used to construct it). You can still limit all rows from db response withlimit_raw_sql=Trueflag on eitherlimitoroffset(or both) - Breaking: issuing
first()now fetches the first row ordered by the primary key asc (so first one inserted (can be different for non number primary keys - i.e. alphabetical order of string)) - Breaking: issuing
get()without any filters now fetches the first row ordered by the primary key desc (so should be last one inserted (can be different for non number primary keys - i.e. alphabetical order of string)) - Breaking (internal): sqlalchemy columns kept at
Meta.columnsare no longer bind to table, so you cannot get the column straight from there
Features
- Introduce inheritance. For now two types of inheritance are possible:
- Mixins - don't subclass
ormar.Model, just define fields that are later used on different models (likecreated_dateandupdated_dateon each child model), only actual models create tables, but those fields from mixins are added - Concrete table inheritance - means that parent is marked as
abstract=Truein Meta class and each child has its own table with columns from the parent and own child columns, kind of similar to Mixins but parent also is a (an abstract) Model - To read more check the docs on models -> inheritance section.
- Mixins - don't subclass
- QuerySet
first()can be used withprefetch_related
Fixes
- Fix minor bug in
order_byfor primary model order bys - Fix in
prefetch_queryfor multiple related_names for the same model. - Fix using same
related_nameon different models leading to the same relatedModeloverwriting each other, nowModelDefinitionErroris raised and you need to change the name. - Fix
order_byoverwriting conditions when multiple joins to the same table applied.
Docs
- Split and cleanup in docs:
- Divide models section into subsections
- Divide relations section into subsections
- Divide fields section into subsections
- Add model inheritance section
- Add API (BETA) documentation