fix for #226
This commit is contained in:
@ -2,6 +2,7 @@ import logging
|
||||
from typing import Dict, List, Optional, TYPE_CHECKING, Tuple, Type, Union
|
||||
|
||||
import sqlalchemy
|
||||
from pydantic.typing import ForwardRef
|
||||
|
||||
import ormar # noqa: I100, I202
|
||||
from ormar.models.descriptors import RelationDescriptor
|
||||
@ -203,7 +204,7 @@ def _is_through_model_not_set(field: "BaseField") -> bool:
|
||||
:return: result of the check
|
||||
:rtype: bool
|
||||
"""
|
||||
return field.is_multi and not field.through
|
||||
return field.is_multi and not field.through and not field.to.__class__ == ForwardRef
|
||||
|
||||
|
||||
def _is_db_field(field: "BaseField") -> bool:
|
||||
|
||||
@ -447,6 +447,9 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
field = cast(ForeignKeyField, field)
|
||||
field.evaluate_forward_ref(globalns=globalns, localns=localns)
|
||||
field.set_self_reference_flag()
|
||||
if field.is_multi and not field.through:
|
||||
field = cast(ormar.ManyToManyField, field)
|
||||
field.create_default_through_model()
|
||||
expand_reverse_relationship(model_field=field)
|
||||
register_relation_in_alias_manager(field=field)
|
||||
update_column_definition(model=cls, field=field)
|
||||
|
||||
Reference in New Issue
Block a user