Skip to content

models.mixins.alias_mixin

AliasMixin Objects

1
class AliasMixin()

Used to translate field names into database column names.

get_column_alias

1
2
 | @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: name of the field to get alias from :type field_name: str

Returns:

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

get_column_name_from_alias

1
2
 | @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: :type alias: str

Returns:

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

translate_columns_to_aliases

1
2
 | @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 with fields names and their values :type new_kwargs: Dict

Returns:

dict with aliases and their values :rtype: Dict

translate_aliases_to_columns

1
2
 | @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 with aliases and their values :type new_kwargs: Dict

Returns:

dict with fields names and their values :rtype: Dict