rename relationshipmanager

This commit is contained in:
collerek
2020-08-23 18:32:21 +02:00
parent fd688d23bd
commit 9bbf6f93ed
8 changed files with 11 additions and 11 deletions

BIN
.coverage

Binary file not shown.

View File

@ -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. 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 ```python
SchoolClass._orm_relationship_manager SchoolClass._orm_relationship_manager

View File

@ -36,6 +36,6 @@ print('department' in course.__dict__)
# False <- related model is not stored on Course instance # False <- related model is not stored on Course instance
print(course.department) print(course.department)
# Department(id=None, name='Science') <- Department model # Department(id=None, name='Science') <- Department model
# returned from RelationshipManager # returned from AliasManager
print(course.department.name) print(course.department.name)
# Science # Science

View File

@ -1,4 +1,4 @@
from ormar.models.model import Model
from ormar.models.newbasemodel import NewBaseModel from ormar.models.newbasemodel import NewBaseModel
from ormar.models.model import Model
__all__ = ["NewBaseModel", "Model"] __all__ = ["NewBaseModel", "Model"]

View File

@ -10,12 +10,12 @@ from ormar import ForeignKey, ModelDefinitionError # noqa I100
from ormar.fields import BaseField from ormar.fields import BaseField
from ormar.fields.foreign_key import ForeignKeyField from ormar.fields.foreign_key import ForeignKeyField
from ormar.queryset import QuerySet from ormar.queryset import QuerySet
from ormar.relations import RelationshipManager from ormar.relations import AliasManager
if TYPE_CHECKING: # pragma no cover if TYPE_CHECKING: # pragma no cover
from ormar import Model from ormar import Model
relationship_manager = RelationshipManager() relationship_manager = AliasManager()
class ModelMeta: class ModelMeta:
@ -26,7 +26,7 @@ class ModelMeta:
columns: List[sqlalchemy.Column] columns: List[sqlalchemy.Column]
pkname: str pkname: str
model_fields: Dict[str, Union[BaseField, ForeignKey]] 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: def register_relation_on_build(table_name: str, field: ForeignKey, name: str) -> None:

View File

@ -22,7 +22,7 @@ import ormar # noqa I100
from ormar.fields import BaseField from ormar.fields import BaseField
from ormar.models.metaclass import ModelMeta, ModelMetaclass from ormar.models.metaclass import ModelMeta, ModelMetaclass
from ormar.models.modelproxy import ModelTableProxy from ormar.models.modelproxy import ModelTableProxy
from ormar.relations import RelationshipManager from ormar.relations import AliasManager
if TYPE_CHECKING: # pragma no cover if TYPE_CHECKING: # pragma no cover
from ormar.models.model import Model from ormar.models.model import Model
@ -45,7 +45,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
__tablename__: str __tablename__: str
__metadata__: sqlalchemy.MetaData __metadata__: sqlalchemy.MetaData
__database__: databases.Database __database__: databases.Database
_orm_relationship_manager: RelationshipManager _orm_relationship_manager: AliasManager
Meta: ModelMeta Meta: ModelMeta
# noinspection PyMissingConstructor # noinspection PyMissingConstructor

View File

@ -6,7 +6,7 @@ from sqlalchemy import text
import ormar # noqa I100 import ormar # noqa I100
from ormar.fields.foreign_key import ForeignKeyField from ormar.fields.foreign_key import ForeignKeyField
from ormar.queryset.relationship_crawler import RelationshipCrawler from ormar.queryset.relationship_crawler import RelationshipCrawler
from ormar.relations import RelationshipManager from ormar.relations import AliasManager
if TYPE_CHECKING: # pragma no cover if TYPE_CHECKING: # pragma no cover
from ormar import Model from ormar import Model
@ -44,7 +44,7 @@ class Query:
self.order_bys = None self.order_bys = None
@property @property
def relation_manager(self) -> RelationshipManager: def relation_manager(self) -> AliasManager:
return self.model_cls.Meta._orm_relationship_manager return self.model_cls.Meta._orm_relationship_manager
def build_select_expression(self) -> Tuple[sqlalchemy.sql.select, List[str]]: def build_select_expression(self) -> Tuple[sqlalchemy.sql.select, List[str]]:

View File

@ -18,7 +18,7 @@ def get_table_alias() -> str:
return "".join(choices(string.ascii_uppercase, k=2)) + uuid.uuid4().hex[:4] return "".join(choices(string.ascii_uppercase, k=2)) + uuid.uuid4().hex[:4]
class RelationshipManager: class AliasManager:
def __init__(self) -> None: def __init__(self) -> None:
self._relations = dict() self._relations = dict()
self._aliases = dict() self._aliases = dict()