Skip to content

Instantly share code, notes, and snippets.

@longfin
Created December 3, 2011 05:11
Show Gist options
  • Save longfin/1426133 to your computer and use it in GitHub Desktop.
Save longfin/1426133 to your computer and use it in GitHub Desktop.
요런 식으로 sqlalchemy의 joinedload, subqueryload를 바꿔치기함
from functools import wraps
def __extend_keys(l):
ret = [[]]
for p in l:
for r in list(ret):
if isinstance(p, list):
ret.remove(r)
for e in p:
nr = list(r)
nr.append(e)
ret.append(nr)
else:
r.append(p)
return ret
def __build_wrapper(f):
@wraps(f)
def wrapper(*keys, **kwargs):
extended = __extend_keys(keys)
if len(extended) == 1:
return f(*keys, **kwargs)
else:
return [f(*k, **kwargs) for k in extended]
return wrapper
orm.joinedload = __build_wrapper(orm.joinedload)
orm.joinedload_all = __build_wrapper(orm.joinedload_all)
orm.subqueryload = __build_wrapper(orm.subqueryload)
orm.subqueryload_all = __build_wrapper(orm.subqueryload_all)
@longfin
Copy link
Author

longfin commented Dec 3, 2011

string도 Iterable이라

    joinedload(ParentPurchase.user_creator, 'facebook_account')

요런 코드에서 바보가 됨 --;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment