diff --git a/.coverage b/.coverage index 7dffaa8..aa90211 100644 Binary files a/.coverage and b/.coverage differ diff --git a/docs/relations.md b/docs/relations.md index 43a6e20..c244673 100644 --- a/docs/relations.md +++ b/docs/relations.md @@ -76,7 +76,7 @@ Since you join two times to the same table (categories) it won't work by default But don't worry - ormar can handle situations like this, as it uses the Relationship Manager which has it's aliases defined for all relationships. -Each class is registered with the same instance of the RelationshipManager that you can access like this: +Each class is registered with the same instance of the AliasManager that you can access like this: ```python SchoolClass._orm_relationship_manager diff --git a/docs_src/models/docs006.py b/docs_src/models/docs006.py index b232979..368e771 100644 --- a/docs_src/models/docs006.py +++ b/docs_src/models/docs006.py @@ -36,6 +36,6 @@ print('department' in course.__dict__) # False <- related model is not stored on Course instance print(course.department) # Department(id=None, name='Science') <- Department model -# returned from RelationshipManager +# returned from AliasManager print(course.department.name) # Science \ No newline at end of file diff --git a/ormar/models/__init__.py b/ormar/models/__init__.py index 53eaff4..bc6e7d0 100644 --- a/ormar/models/__init__.py +++ b/ormar/models/__init__.py @@ -1,4 +1,4 @@ -from ormar.models.model import Model from ormar.models.newbasemodel import NewBaseModel +from ormar.models.model import Model __all__ = ["NewBaseModel", "Model"] diff --git a/ormar/models/metaclass.py b/ormar/models/metaclass.py index aa65c74..43fc0ca 100644 --- a/ormar/models/metaclass.py +++ b/ormar/models/metaclass.py @@ -10,12 +10,12 @@ from ormar import ForeignKey, ModelDefinitionError # noqa I100 from ormar.fields import BaseField from ormar.fields.foreign_key import ForeignKeyField from ormar.queryset import QuerySet -from ormar.relations import RelationshipManager +from ormar.relations import AliasManager if TYPE_CHECKING: # pragma no cover from ormar import Model -relationship_manager = RelationshipManager() +relationship_manager = AliasManager() class ModelMeta: @@ -26,7 +26,7 @@ class ModelMeta: columns: List[sqlalchemy.Column] pkname: str model_fields: Dict[str, Union[BaseField, ForeignKey]] - _orm_relationship_manager: RelationshipManager + _orm_relationship_manager: AliasManager def register_relation_on_build(table_name: str, field: ForeignKey, name: str) -> None: diff --git a/ormar/models/newbasemodel.py b/ormar/models/newbasemodel.py index 932e2c2..0f09893 100644 --- a/ormar/models/newbasemodel.py +++ b/ormar/models/newbasemodel.py @@ -22,7 +22,7 @@ import ormar # noqa I100 from ormar.fields import BaseField from ormar.models.metaclass import ModelMeta, ModelMetaclass from ormar.models.modelproxy import ModelTableProxy -from ormar.relations import RelationshipManager +from ormar.relations import AliasManager if TYPE_CHECKING: # pragma no cover from ormar.models.model import Model @@ -45,7 +45,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass __tablename__: str __metadata__: sqlalchemy.MetaData __database__: databases.Database - _orm_relationship_manager: RelationshipManager + _orm_relationship_manager: AliasManager Meta: ModelMeta # noinspection PyMissingConstructor diff --git a/ormar/queryset/query.py b/ormar/queryset/query.py index b4c91c2..6b04b6d 100644 --- a/ormar/queryset/query.py +++ b/ormar/queryset/query.py @@ -6,7 +6,7 @@ from sqlalchemy import text import ormar # noqa I100 from ormar.fields.foreign_key import ForeignKeyField from ormar.queryset.relationship_crawler import RelationshipCrawler -from ormar.relations import RelationshipManager +from ormar.relations import AliasManager if TYPE_CHECKING: # pragma no cover from ormar import Model @@ -44,7 +44,7 @@ class Query: self.order_bys = None @property - def relation_manager(self) -> RelationshipManager: + def relation_manager(self) -> AliasManager: return self.model_cls.Meta._orm_relationship_manager def build_select_expression(self) -> Tuple[sqlalchemy.sql.select, List[str]]: diff --git a/ormar/relations.py b/ormar/relations.py index d6b7616..6177f26 100644 --- a/ormar/relations.py +++ b/ormar/relations.py @@ -18,7 +18,7 @@ def get_table_alias() -> str: return "".join(choices(string.ascii_uppercase, k=2)) + uuid.uuid4().hex[:4] -class RelationshipManager: +class AliasManager: def __init__(self) -> None: self._relations = dict() self._aliases = dict()