def _handle_through_fields_and_prefix(
        self,
        model_cls: Type["Model"],
        field: "ForeignKeyField",
        previous_related_str: str,
        relation: str,
    ) -> str:
        """
        Registers through models for m2m relations and switches prefix for
        the one linking from through model to target model.

        For other relations returns current model name + relation name as prefix.
        Nested relations are a chain of relation names with __ in between.

        :param model_cls: model of current relation
        :type model_cls: Type["Model"]
        :param field: field with relation
        :type field: ForeignKeyField
        :param previous_related_str: concatenated chain linked with "__"
        :type previous_related_str: str
        :param relation: name of the current relation in chain
        :type relation: str
        :return: name of prefix to populate
        :rtype: str
        """
        prefix_name = f"{model_cls.get_name()}_{relation}"
        if field.is_multi:
            through_name = field.through.get_name()
            if not self.exclude_through:
                self._fields[prefix_name] = field
                new_through_str = previous_related_str + through_name
                self._prefixes[prefix_name] = new_through_str
            prefix_name = f"{through_name}_{field.default_target_field_name()}"
        return prefix_name

        Registers through models for m2m relations and switches prefix for
        the one linking from through model to target model.

        For other relations returns current model name + relation name as prefix.
        Nested relations are a chain of relation names with __ in between.

        :param model_cls: model of current relation
        :type model_cls: Type["Model"]
        :param field: field with relation
        :type field: ForeignKeyField
        :param previous_related_str: concatenated chain linked with "__"
        :type previous_related_str: str
        :param relation: name of the current relation in chain
        :type relation: str
        :return: name of prefix to populate
        :rtype: str
        
ormar/queryset/reverse_alias_resolver.py