Files
ormar/docs/api/models/mixins/alias-mixin.md

2.1 KiB

models.mixins.alias_mixin

AliasMixin Objects

class AliasMixin()

Used to translate field names into database column names.

get_column_alias

 | @classmethod
 | get_column_alias(cls, field_name: str) -> str

Returns db alias (column name in db) for given ormar field. For fields without alias field name is returned.

Arguments:

  • field_name (str): name of the field to get alias from

Returns:

(str): alias (db name) if set, otherwise passed name

get_column_name_from_alias

 | @classmethod
 | get_column_name_from_alias(cls, alias: str) -> str

Returns ormar field name for given db alias (column name in db). If field do not have alias it's returned as is.

Arguments:

  • alias (str):

Returns:

(str): field name if set, otherwise passed alias (db name)

translate_columns_to_aliases

 | @classmethod
 | translate_columns_to_aliases(cls, new_kwargs: Dict) -> Dict

Translates dictionary of model fields changing field names into aliases. If field has no alias the field name remains intact. Only fields present in the dictionary are translated.

Arguments:

  • new_kwargs (Dict): dict with fields names and their values

Returns:

(Dict): dict with aliases and their values

translate_aliases_to_columns

 | @classmethod
 | translate_aliases_to_columns(cls, new_kwargs: Dict) -> Dict

Translates dictionary of model fields changing aliases into field names. If field has no alias the alias is already a field name. Only fields present in the dictionary are translated.

Arguments:

  • new_kwargs (Dict): dict with aliases and their values

Returns:

(Dict): dict with fields names and their values