def replace_models_with_copy(
    annotation: Type, source_model_field: Optional[str] = None
) -> Any:
    """
    Replaces all models in annotation with their copies to avoid circular references.

    :param annotation: annotation to replace models in
    :type annotation: Type
    :return: annotation with replaced models
    :rtype: Type
    """
    if inspect.isclass(annotation) and issubclass(annotation, ormar.Model):
        return create_copy_to_avoid_circular_references(model=annotation)
    elif hasattr(annotation, "__origin__") and annotation.__origin__ in {list, Union}:
        if annotation.__origin__ is list:
            return List[  # type: ignore
                replace_models_with_copy(
                    annotation=annotation.__args__[0],
                    source_model_field=source_model_field,
                )
            ]
        elif annotation.__origin__ == Union:
            args = annotation.__args__
            new_args = [
                replace_models_with_copy(
                    annotation=arg, source_model_field=source_model_field
                )
                for arg in args
            ]
            return Union[tuple(new_args)]
    else:
        return annotation

    Replaces all models in annotation with their copies to avoid circular references.

    :param annotation: annotation to replace models in
    :type annotation: Type
    :return: annotation with replaced models
    :rtype: Type
    
ormar/models/helpers/relations.py