Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #13, enhance Alias usage #326

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gino/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down