diff options
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r-- | lib/sqlalchemy/orm/query.py | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index beabc5811..ebfcf1087 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -24,7 +24,8 @@ from . import ( attributes, interfaces, object_mapper, persistence, exc as orm_exc, loading ) -from .base import _entity_descriptor, _is_aliased_class, _is_mapped_class, _orm_columns +from .base import _entity_descriptor, _is_aliased_class, \ + _is_mapped_class, _orm_columns, _generative from .path_registry import PathRegistry from .util import ( AliasedClass, ORMAdapter, join as orm_join, with_parent, aliased @@ -42,18 +43,6 @@ from . import properties __all__ = ['Query', 'QueryContext', 'aliased'] -def _generative(*assertions): - """Mark a method as generative.""" - - @util.decorator - def generate(fn, *args, **kw): - self = args[0]._clone() - for assertion in assertions: - assertion(self, fn.__name__) - fn(self, *args[1:], **kw) - return self - return generate - _path_registry = PathRegistry.root @inspection._self_inspects @@ -3438,28 +3427,29 @@ class QueryContext(object): class AliasOption(interfaces.MapperOption): def __init__(self, alias): - """Return a :class:`.MapperOption` that will indicate to the query that - the main table has been aliased. + """Return a :class:`.MapperOption` that will indicate to the :class:`.Query` + that the main table has been aliased. - This is used in the very rare case that :func:`.contains_eager` + This is a seldom-used option to suit the + very rare case that :func:`.contains_eager` is being used in conjunction with a user-defined SELECT statement that aliases the parent table. E.g.:: # define an aliased UNION called 'ulist' - statement = users.select(users.c.user_id==7).\\ + ulist = users.select(users.c.user_id==7).\\ union(users.select(users.c.user_id>7)).\\ alias('ulist') # add on an eager load of "addresses" - statement = statement.outerjoin(addresses).\\ + statement = ulist.outerjoin(addresses).\\ select().apply_labels() # create query, indicating "ulist" will be an # alias for the main table, "addresses" # property should be eager loaded query = session.query(User).options( - contains_alias('ulist'), - contains_eager('addresses')) + contains_alias(ulist), + contains_eager(User.addresses)) # then get results via the statement results = query.from_statement(statement).all() |