From 1b25ed907fb7311d28d2273c9b9858b50c1a7afc Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 6 Oct 2013 20:29:08 -0400 Subject: - merge ticket_1418 branch, [ticket:1418] - The system of loader options has been entirely rearchitected to build upon a much more comprehensive base, the :class:`.Load` object. This base allows any common loader option like :func:`.joinedload`, :func:`.defer`, etc. to be used in a "chained" style for the purpose of specifying options down a path, such as ``joinedload("foo").subqueryload("bar")``. The new system supersedes the usage of dot-separated path names, multiple attributes within options, and the usage of ``_all()`` options. - Added a new load option :func:`.orm.load_only`. This allows a series of column names to be specified as loading "only" those attributes, deferring the rest. --- lib/sqlalchemy/orm/query.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'lib/sqlalchemy/orm/query.py') 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() -- cgit v1.2.1