Skip to content

Commit af04a19

Browse files
committed
refs #13, enhance Alias usage
fix the issue that Alias methods like outjoin invoked Model, which caused the loader couldn't find corresponding columns.
1 parent 8cb61a2 commit af04a19

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

gino/crud.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def __init__(self, model, *args, **kwargs):
234234

235235
def __getattr__(self, item):
236236
rv = getattr(self.alias.columns, item,
237-
getattr(self.model, item,
238-
getattr(self.alias, item, DEFAULT)))
237+
getattr(self.alias, item,
238+
getattr(self.model, item, DEFAULT)))
239239
if rv is DEFAULT:
240240
raise AttributeError
241241
return rv

tests/test_loader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from async_generator import yield_, async_generator
66

7+
from gino.loader import AliasLoader
78
from .models import db, User, Team, Company
89

910
pytestmark = pytest.mark.asyncio
@@ -144,6 +145,15 @@ def loader(row, context):
144145
assert u.team.parent.name == user.team.parent.name
145146

146147

148+
async def test_alias_loader_columns(user):
149+
user_alias = User.alias()
150+
base_query = user_alias.outerjoin(Team).select()
151+
152+
query = base_query.execution_options(loader=AliasLoader(user_alias, 'id'))
153+
u = await query.gino.first()
154+
assert u.id is not None
155+
156+
147157
async def test_adjacency_list_query_builder(user):
148158
group = Team.alias()
149159
u = await User.load(team=Team.load(parent=group.on(

0 commit comments

Comments
 (0)