summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/query.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
-rw-r--r--lib/sqlalchemy/orm/query.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 94c6e1776..e53eedda2 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -6,11 +6,11 @@
"""The Query class and support.
-Defines the :class:`~sqlalchemy.orm.query.Query` class, the central
+Defines the :class:`.Query` class, the central
construct used by the ORM to construct database queries.
-The ``Query`` class should not be confused with the
-:class:`~sqlalchemy.sql.expression.Select` class, which defines database
+The :class:`.Query` class should not be confused with the
+:class:`.Select` class, which defines database
SELECT operations at the SQL (non-ORM) level. ``Query`` differs from
``Select`` in that it returns ORM-mapped objects and interacts with an
ORM session, whereas the ``Select`` construct interacts directly with the
@@ -596,6 +596,25 @@ class Query(object):
@_generative()
def correlate(self, *args):
+ """Return a :class:`.Query` construct which will correlate the given
+ FROM clauses to that of an enclosing :class:`.Query` or
+ :func:`~.expression.select`.
+
+ The method here accepts mapped classes, :func:`.aliased` constructs,
+ and :func:`.mapper` constructs as arguments, which are resolved into
+ expression constructs, in addition to appropriate expression
+ constructs.
+
+ The correlation arguments are ultimately passed to
+ :meth:`.Select.correlate` after coercion to expression constructs.
+
+ The correlation arguments take effect in such cases
+ as when :meth:`.Query.from_self` is used, or when
+ a subquery as returned by :meth:`.Query.subquery` is
+ embedded in another :func:`~.expression.select` construct.
+
+ """
+
self._correlate = self._correlate.union(
_orm_selectable(s)
for s in args)
@@ -2547,8 +2566,12 @@ class _MapperEntity(_QueryEntity):
)
)
- for value in self.mapper._iterate_polymorphic_properties(
- self._with_polymorphic):
+ if self._with_polymorphic:
+ poly_properties = self.mapper._iterate_polymorphic_properties(
+ self._with_polymorphic)
+ else:
+ poly_properties = self.mapper._polymorphic_properties
+ for value in poly_properties:
if query._only_load_props and \
value.key not in query._only_load_props:
continue