summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/query.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-10-06 20:29:08 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-10-06 20:29:08 -0400
commit1b25ed907fb7311d28d2273c9b9858b50c1a7afc (patch)
tree74bd8df8638dbd1f1e48b1ca660963944be0be3d /lib/sqlalchemy/orm/query.py
parentd79e1d69a6b2d0d1cc18d3d9d0283ef4a77925bc (diff)
downloadsqlalchemy-1b25ed907fb7311d28d2273c9b9858b50c1a7afc.tar.gz
- 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.
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r--lib/sqlalchemy/orm/query.py30
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()