From af04a19750b26bfec6a43c97da3acc06b58fb97a Mon Sep 17 00:00:00 2001 From: Tony Wang Date: Wed, 5 Sep 2018 01:34:26 +0800 Subject: [PATCH] refs #13, enhance Alias usage fix the issue that Alias methods like outjoin invoked Model, which caused the loader couldn't find corresponding columns. --- gino/crud.py | 4 ++-- tests/test_loader.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gino/crud.py b/gino/crud.py index a1e6158b..1b39a5cf 100644 --- a/gino/crud.py +++ b/gino/crud.py @@ -234,8 +234,8 @@ def __init__(self, model, *args, **kwargs): def __getattr__(self, item): rv = getattr(self.alias.columns, item, - getattr(self.model, item, - getattr(self.alias, item, DEFAULT))) + getattr(self.alias, item, + getattr(self.model, item, DEFAULT))) if rv is DEFAULT: raise AttributeError return rv diff --git a/tests/test_loader.py b/tests/test_loader.py index 0a5104d8..67a979ff 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -4,6 +4,7 @@ import pytest from async_generator import yield_, async_generator +from gino.loader import AliasLoader from .models import db, User, Team, Company pytestmark = pytest.mark.asyncio @@ -144,6 +145,15 @@ def loader(row, context): assert u.team.parent.name == user.team.parent.name +async def test_alias_loader_columns(user): + user_alias = User.alias() + base_query = user_alias.outerjoin(Team).select() + + query = base_query.execution_options(loader=AliasLoader(user_alias, 'id')) + u = await query.gino.first() + assert u.id is not None + + async def test_adjacency_list_query_builder(user): group = Team.alias() u = await User.load(team=Team.load(parent=group.on(