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.py306
1 files changed, 153 insertions, 153 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 53c777ae8..d5f0ef0ca 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -55,20 +55,20 @@ def _generative(*assertions):
class Query(object):
"""ORM-level SQL construction object.
-
+
:class:`.Query` is the source of all SELECT statements generated by the
ORM, both those formulated by end-user query operations as well as by
high level internal operations such as related collection loading. It
features a generative interface whereby successive calls return a new
:class:`.Query` object, a copy of the former with additional
criteria and options associated with it.
-
+
:class:`.Query` objects are normally initially generated using the
:meth:`~.Session.query` method of :class:`.Session`. For a full walkthrough
of :class:`.Query` usage, see the :ref:`ormtutorial_toplevel`.
-
+
"""
-
+
_enable_eagerloads = True
_enable_assertions = True
_with_labels = False
@@ -100,7 +100,7 @@ class Query(object):
_with_options = ()
_with_hints = ()
_enable_single_crit = True
-
+
def __init__(self, entities, session=None):
self.session = session
self._polymorphic_adapters = {}
@@ -173,7 +173,7 @@ class Query(object):
equivs = self.__all_equivs()
self._from_obj_alias = sql_util.ColumnAdapter(
self._from_obj[0], equivs)
-
+
def _get_polymorphic_adapter(self, entity, selectable):
self.__mapper_loads_polymorphically_with(entity.mapper,
sql_util.ColumnAdapter(selectable,
@@ -226,7 +226,7 @@ class Query(object):
@_generative()
def _adapt_all_clauses(self):
self._disable_orm_filtering = True
-
+
def _adapt_col_list(self, cols):
return [
self._adapt_clause(
@@ -234,7 +234,7 @@ class Query(object):
True, True)
for o in cols
]
-
+
def _adapt_clause(self, clause, as_filter, orm_only):
adapters = []
if as_filter and self._filter_aliases:
@@ -323,7 +323,7 @@ class Query(object):
def _get_condition(self):
self._order_by = self._distinct = False
return self._no_criterion_condition("get")
-
+
def _no_criterion_condition(self, meth):
if not self._enable_assertions:
return
@@ -407,11 +407,11 @@ class Query(object):
@property
def statement(self):
"""The full SELECT statement represented by this Query.
-
+
The statement by default will not have disambiguating labels
applied to the construct unless with_labels(True) is called
first.
-
+
"""
stmt = self._compile_context(labels=self._with_labels).\
@@ -432,33 +432,33 @@ class Query(object):
"""
return self.enable_eagerloads(False).statement.alias()
-
+
def label(self, name):
"""Return the full SELECT statement represented by this :class:`.Query`, converted
to a scalar subquery with a label of the given name.
-
+
Analagous to :meth:`sqlalchemy.sql._SelectBaseMixin.label`.
-
+
New in 0.6.5.
"""
-
+
return self.enable_eagerloads(False).statement.label(name)
def as_scalar(self):
"""Return the full SELECT statement represented by this :class:`.Query`, converted
to a scalar subquery.
-
+
Analagous to :meth:`sqlalchemy.sql._SelectBaseMixin.as_scalar`.
New in 0.6.5.
-
+
"""
-
+
return self.enable_eagerloads(False).statement.as_scalar()
-
-
+
+
def __clause_element__(self):
return self.enable_eagerloads(False).with_labels().statement
@@ -495,11 +495,11 @@ class Query(object):
"""
self._with_labels = True
-
+
@_generative()
def enable_assertions(self, value):
"""Control whether assertions are generated.
-
+
When set to False, the returned Query will
not assert its state before certain operations,
including that LIMIT/OFFSET has not been applied
@@ -509,22 +509,22 @@ class Query(object):
is called. This more permissive mode is used by
custom Query subclasses to specify criterion or
other modifiers outside of the usual usage patterns.
-
+
Care should be taken to ensure that the usage
pattern is even possible. A statement applied
by from_statement() will override any criterion
set by filter() or order_by(), for example.
-
+
"""
self._enable_assertions = value
-
+
@property
def whereclause(self):
"""A readonly attribute which returns the current WHERE criterion for this Query.
-
+
This returned value is a SQL expression construct, or ``None`` if no
criterion has been established.
-
+
"""
return self._criterion
@@ -601,12 +601,12 @@ class Query(object):
set the ``stream_results`` execution
option to ``True``, which currently is only understood by psycopg2
and causes server side cursors to be used.
-
+
"""
self._yield_per = count
self._execution_options = self._execution_options.copy()
self._execution_options['stream_results'] = True
-
+
def get(self, ident):
"""Return an instance of the object based on the
given identifier, or None if not found.
@@ -621,9 +621,9 @@ class Query(object):
# convert composite types to individual args
if hasattr(ident, '__composite_values__'):
ident = ident.__composite_values__()
-
+
ident = util.to_list(ident)
-
+
mapper = self._only_mapper_zero(
"get() can only be used against a single mapped class."
)
@@ -633,13 +633,13 @@ class Query(object):
"Incorrect number of values in identifier to formulate "
"primary key for query.get(); primary key columns are %s" %
','.join("'%s'" % c for c in mapper.primary_key))
-
+
key = mapper.identity_key_from_primary_key(ident)
if not self._populate_existing and \
not mapper.always_refresh and \
self._lockmode is None:
-
+
instance = self._get_from_identity(self.session, key, False)
if instance is not None:
# reject calls for id in identity map but class
@@ -655,22 +655,22 @@ class Query(object):
"""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)
@@ -691,7 +691,7 @@ class Query(object):
def populate_existing(self):
"""Return a :class:`Query` that will expire and refresh all instances
as they are loaded, or reused from the current :class:`.Session`.
-
+
:meth:`.populate_existing` does not improve behavior when
the ORM is used normally - the :class:`.Session` object's usual
behavior of maintaining a transaction and expiring all attributes
@@ -706,16 +706,16 @@ class Query(object):
to a child object or collection, using its attribute state
as well as an established :func:`.relationship()`
configuration.
-
+
The method uses the :func:`.with_parent` function to generate
the clause, the result of which is passed to :meth:`.Query.filter`.
-
+
Parameters are the same as :func:`.with_parent`, with the exception
that the given property can be None, in which case a search is
performed against this :class:`.Query` object's target mapper.
-
+
"""
-
+
if property is None:
from sqlalchemy.orm import properties
mapper = object_mapper(instance)
@@ -767,7 +767,7 @@ class Query(object):
@_generative()
def _enable_single_crit(self, val):
self._enable_single_crit = val
-
+
@_generative()
def _from_selectable(self, fromclause):
for attr in ('_statement', '_criterion', '_order_by', '_group_by',
@@ -805,12 +805,12 @@ class Query(object):
# end Py2K
except StopIteration:
return None
-
+
@_generative()
def with_entities(self, *entities):
"""Return a new :class:`.Query` replacing the SELECT list with the given
entities.
-
+
e.g.::
# Users, filtered on some arbitrary criterion
@@ -830,11 +830,11 @@ class Query(object):
limit(1)
New in 0.6.5.
-
+
"""
self._set_entities(entities)
-
-
+
+
@_generative()
def add_columns(self, *column):
"""Add one or more column expressions to the list
@@ -853,23 +853,23 @@ class Query(object):
False)
def add_column(self, column):
"""Add a column expression to the list of result columns to be returned.
-
+
Pending deprecation: :meth:`.add_column` will be superceded by
:meth:`.add_columns`.
-
+
"""
-
+
return self.add_columns(column)
def options(self, *args):
"""Return a new Query object, applying the given list of
mapper options.
-
+
Most supplied options regard changing how column- and
relationship-mapped attributes are loaded. See the sections
:ref:`deferred` and :ref:`loading_toplevel` for reference
documentation.
-
+
"""
return self._options(False, *args)
@@ -894,7 +894,7 @@ class Query(object):
def with_hint(self, selectable, text, dialect_name='*'):
"""Add an indexing hint for the given entity or selectable to
this :class:`Query`.
-
+
Functionality is passed straight through to
:meth:`~sqlalchemy.sql.expression.Select.with_hint`,
with the addition that ``selectable`` can be a
@@ -902,16 +902,16 @@ class Query(object):
/etc.
"""
mapper, selectable, is_aliased_class = _entity_info(selectable)
-
+
self._with_hints += ((selectable, text, dialect_name),)
-
+
@_generative()
def execution_options(self, **kwargs):
""" Set non-SQL options which take effect during execution.
-
+
The options are the same as those accepted by
:meth:`sqlalchemy.sql.expression.Executable.execution_options`.
-
+
Note that the ``stream_results`` execution option is enabled
automatically if the :meth:`~sqlalchemy.orm.query.Query.yield_per()`
method is used.
@@ -982,16 +982,16 @@ class Query(object):
def order_by(self, *criterion):
"""apply one or more ORDER BY criterion to the query and return
the newly resulting ``Query``
-
+
All existing ORDER BY settings can be suppressed by
passing ``None`` - this will suppress any ORDER BY configured
on mappers as well.
-
+
Alternatively, an existing ORDER BY setting on the Query
object can be entirely cancelled by passing ``False``
as the value - use this before calling methods where
an ORDER BY is invalid.
-
+
"""
if len(criterion) == 1:
@@ -1002,7 +1002,7 @@ class Query(object):
if criterion[0] is None:
self._order_by = None
return
-
+
criterion = self._adapt_col_list(criterion)
if self._order_by is False or self._order_by is None:
@@ -1075,8 +1075,8 @@ class Query(object):
SELECT * FROM Z)
"""
-
-
+
+
return self._from_selectable(
expression.union(*([self]+ list(q))))
@@ -1200,15 +1200,15 @@ class Query(object):
to join from the right endpoint of the most recent join(),
instead of from the query's root entity. I.e. any chain
of joins, such as::
-
+
query.join(a, b, c)
-
+
is equivalent to::
-
+
query.join(a).\\
join(b, from_joinpoint=True).\\
join(c, from_joinpoint=True)
-
+
"""
aliased, from_joinpoint = kwargs.pop('aliased', False),\
kwargs.pop('from_joinpoint', False)
@@ -1239,13 +1239,13 @@ class Query(object):
def _join(self, keys, outerjoin, create_aliases, from_joinpoint):
"""consumes arguments from join() or outerjoin(), places them into a
consistent format with which to form the actual JOIN constructs.
-
+
"""
self._polymorphic_adapters = self._polymorphic_adapters.copy()
if not from_joinpoint:
self._reset_joinpoint()
-
+
if len(keys) == 2 and \
isinstance(keys[0], (expression.FromClause,
type, AliasedClass)) and \
@@ -1264,7 +1264,7 @@ class Query(object):
arg1, arg2 = arg1
else:
arg2 = None
-
+
# determine onclause/right_entity. there
# is a little bit of legacy behavior still at work here
# which means they might be in either order. may possibly
@@ -1275,19 +1275,19 @@ class Query(object):
right_entity, onclause = arg1, arg2
left_entity = prop = None
-
+
if isinstance(onclause, basestring):
left_entity = self._joinpoint_zero()
descriptor = _entity_descriptor(left_entity, onclause)
onclause = descriptor
-
+
# check for q.join(Class.propname, from_joinpoint=True)
# and Class is that of the current joinpoint
elif from_joinpoint and \
isinstance(onclause, interfaces.PropComparator):
left_entity = onclause.parententity
-
+
left_mapper, left_selectable, left_is_aliased = \
_entity_info(self._joinpoint_zero())
if left_mapper is left_entity:
@@ -1304,9 +1304,9 @@ class Query(object):
right_entity = of_type
else:
right_entity = onclause.property.mapper
-
+
left_entity = onclause.parententity
-
+
prop = onclause.property
if not isinstance(onclause, attributes.QueryableAttribute):
onclause = prop
@@ -1324,7 +1324,7 @@ class Query(object):
elif onclause is not None and right_entity is None:
# TODO: no coverage here
raise NotImplementedError("query.join(a==b) not supported.")
-
+
self._join_left_to_right(
left_entity,
right_entity, onclause,
@@ -1333,7 +1333,7 @@ class Query(object):
def _join_left_to_right(self, left, right,
onclause, outerjoin, create_aliases, prop):
"""append a JOIN to the query's from clause."""
-
+
if left is None:
left = self._joinpoint_zero()
@@ -1343,7 +1343,7 @@ class Query(object):
"Can't construct a join from %s to %s, they "
"are the same entity" %
(left, right))
-
+
left_mapper, left_selectable, left_is_aliased = _entity_info(left)
right_mapper, right_selectable, right_is_aliased = _entity_info(right)
@@ -1410,7 +1410,7 @@ class Query(object):
self._joinpoint = {
'_joinpoint_entity':right
}
-
+
# if an alias() of the right side was generated here,
# apply an adapter to all subsequent filter() calls
# until reset_joinpoint() is called.
@@ -1423,7 +1423,7 @@ class Query(object):
# adapters that are in place right now
if isinstance(onclause, expression.ClauseElement):
onclause = self._adapt_clause(onclause, True, True)
-
+
# if an alias() on the right side was generated,
# which is intended to wrap a the right side in a subquery,
# ensure that columns retrieved from this target in the result
@@ -1436,7 +1436,7 @@ class Query(object):
equivalents=right_mapper._equivalent_columns
)
)
-
+
# this is an overly broad assumption here, but there's a
# very wide variety of situations where we rely upon orm.join's
# adaption to glue clauses together, with joined-table inheritance's
@@ -1446,7 +1446,7 @@ class Query(object):
# adaption should be enabled (or perhaps that we're even doing the
# whole thing the way we are here).
join_to_left = not right_is_aliased and not left_is_aliased
-
+
if self._from_obj and left_selectable is not None:
replace_clause_index, clause = sql_util.find_join_source(
self._from_obj,
@@ -1457,13 +1457,13 @@ class Query(object):
# ensure it adapts to the left side.
if self._from_obj_alias and clause is self._from_obj[0]:
join_to_left = True
-
+
# An exception case where adaption to the left edge is not
# desirable. See above note on join_to_left.
if join_to_left and isinstance(clause, expression.Join) and \
sql_util.clause_is_present(left_selectable, clause):
join_to_left = False
-
+
clause = orm_join(clause,
right,
onclause, isouter=outerjoin,
@@ -1491,7 +1491,7 @@ class Query(object):
clause = orm_join(clause, right, onclause,
isouter=outerjoin, join_to_left=join_to_left)
-
+
self._from_obj = self._from_obj + (clause,)
def _reset_joinpoint(self):
@@ -1513,16 +1513,16 @@ class Query(object):
@_generative(_no_clauseelement_condition)
def select_from(self, *from_obj):
"""Set the FROM clause of this :class:`.Query` explicitly.
-
+
Sending a mapped class or entity here effectively replaces the
"left edge" of any calls to :meth:`.Query.join`, when no
joinpoint is otherwise established - usually, the default "join
point" is the leftmost entity in the :class:`.Query` object's
list of entities to be selected.
-
+
Mapped entities or plain :class:`.Table` or other selectables
can be sent here which will form the default FROM clause.
-
+
"""
obj = []
for fo in from_obj:
@@ -1534,10 +1534,10 @@ class Query(object):
raise sa_exc.ArgumentError(
"select_from() accepts FromClause objects only.")
else:
- obj.append(fo)
-
+ obj.append(fo)
+
self._set_select_from(*obj)
-
+
def __getitem__(self, item):
if isinstance(item, slice):
start, stop, step = util.decode_slice(item)
@@ -1568,7 +1568,7 @@ class Query(object):
def slice(self, start, stop):
"""apply LIMIT/OFFSET to the ``Query`` based on a "
"range and return the newly resulting ``Query``."""
-
+
if start is not None and stop is not None:
self._offset = (self._offset or 0) + start
self._limit = stop - start
@@ -1637,7 +1637,7 @@ class Query(object):
def first(self):
"""Return the first result of this ``Query`` or
None if the result doesn't contain any row.
-
+
first() applies a limit of one within the generated SQL, so that
only one primary entity row is generated on the server side
(note this may consist of multiple result rows if join-loaded
@@ -1663,7 +1663,7 @@ class Query(object):
if multiple object identities are returned, or if multiple
rows are returned for a query that does not return object
identities.
-
+
Note that an entity query, that is, one which selects one or
more mapped classes as opposed to individual column attributes,
may ultimately represent many rows but only one row of
@@ -1676,7 +1676,7 @@ class Query(object):
"""
ret = list(self)
-
+
l = len(ret)
if l == 1:
return ret[0]
@@ -1726,20 +1726,20 @@ class Query(object):
clause = querycontext.statement,
close_with_result=True).execute(querycontext.statement, self._params)
return self.instances(result, querycontext)
-
+
@property
def column_descriptions(self):
"""Return metadata about the columns which would be
returned by this :class:`Query`.
-
+
Format is a list of dictionaries::
-
+
user_alias = aliased(User, name='user2')
q = sess.query(User, User.id, user_alias)
-
+
# this expression:
q.columns
-
+
# would return:
[
{
@@ -1761,7 +1761,7 @@ class Query(object):
'expr':user_alias
}
]
-
+
"""
return [
{
@@ -1772,7 +1772,7 @@ class Query(object):
}
for ent in self._entities
]
-
+
def instances(self, cursor, __context=None):
"""Given a ResultProxy cursor as returned by connection.execute(),
return an ORM result as an iterator.
@@ -1810,8 +1810,8 @@ class Query(object):
query_entity.row_processor(self, context, custom_rows)
for query_entity in self._entities
])
-
-
+
+
while True:
context.progress = {}
context.partials = {}
@@ -1855,7 +1855,7 @@ class Query(object):
def merge_result(self, iterator, load=True):
"""Merge a result into this Query's Session.
-
+
Given an iterator returned by a Query of the same structure as this
one, return an identical iterator of results, with all mapped
instances merged into the session using Session.merge(). This is an
@@ -1863,19 +1863,19 @@ class Query(object):
structure of the result rows and unmapped columns with less method
overhead than that of calling Session.merge() explicitly for each
value.
-
+
The structure of the results is determined based on the column list of
this Query - if these do not correspond, unchecked errors will occur.
-
+
The 'load' argument is the same as that of Session.merge().
-
+
"""
-
+
session = self.session
if load:
# flush current contents if we expect to load data
session._autoflush()
-
+
autoflush = session.autoflush
try:
session.autoflush = False
@@ -1900,23 +1900,23 @@ class Query(object):
attributes.instance_state(newrow[i]),
attributes.instance_dict(newrow[i]),
load=load, _recursive={})
- result.append(util.NamedTuple(newrow, row._labels))
-
+ result.append(util.NamedTuple(newrow, row._labels))
+
return iter(result)
finally:
session.autoflush = autoflush
-
+
@classmethod
def _get_from_identity(cls, session, key, passive):
"""Look up the given key in the given session's identity map,
check the object for expired state if found.
-
+
"""
instance = session.identity_map.get(key)
if instance:
-
+
state = attributes.instance_state(instance)
-
+
# expired - ensure it still exists
if state.expired:
if passive is attributes.PASSIVE_NO_FETCH:
@@ -1930,18 +1930,18 @@ class Query(object):
return instance
else:
return None
-
+
def _load_on_ident(self, key, refresh_state=None, lockmode=None,
only_load_props=None):
"""Load the given identity key from the database."""
-
+
lockmode = lockmode or self._lockmode
if key is not None:
ident = key[1]
else:
ident = None
-
+
if refresh_state is None:
q = self._clone()
q._get_condition()
@@ -1952,7 +1952,7 @@ class Query(object):
mapper = self._mapper_zero()
(_get_clause, _get_params) = mapper._get_clause
-
+
# None present in ident - turn those comparisons
# into "IS NULL"
if None in ident:
@@ -1962,7 +1962,7 @@ class Query(object):
])
_get_clause = sql_util.adapt_criterion_to_null(
_get_clause, nones)
-
+
_get_clause = q._adapt_clause(_get_clause, True, False)
q._criterion = _get_clause
@@ -2006,7 +2006,7 @@ class Query(object):
def count(self):
"""Return a count of rows this Query would return.
-
+
For simple entity queries, count() issues
a SELECT COUNT, and will specifically count the primary
key column of the first entity only. If the query uses
@@ -2014,11 +2014,11 @@ class Query(object):
generated by this Query in a subquery, from which a SELECT COUNT
is issued, so that the contract of "how many rows
would be returned?" is honored.
-
+
For queries that request specific columns or expressions,
count() again makes no assumptions about those expressions
and will wrap everything in a subquery. Therefore,
- ``Query.count()`` is usually not what you want in this case.
+ ``Query.count()`` is usually not what you want in this case.
To count specific columns, often in conjunction with
GROUP BY, use ``func.count()`` as an individual column expression
instead of ``Query.count()``. See the ORM tutorial
@@ -2081,7 +2081,7 @@ class Query(object):
:param synchronize_session: chooses the strategy for the removal of
matched objects from the session. Valid values are:
-
+
False - don't synchronize the session. This option is the most
efficient and is reliable once the session is expired, which
typically occurs after a commit(), or explicitly using
@@ -2099,7 +2099,7 @@ class Query(object):
the objects in the session. If evaluation of the criteria isn't
implemented, an error is raised. In that case you probably
want to use the 'fetch' strategy as a fallback.
-
+
The expression evaluator currently doesn't account for differing
string collations between the database and Python.
@@ -2149,7 +2149,7 @@ class Query(object):
else:
def eval_condition(obj):
return True
-
+
except evaluator.UnevaluatableError:
raise sa_exc.InvalidRequestError(
"Could not evaluate current criteria in Python. "
@@ -2214,7 +2214,7 @@ class Query(object):
expire_all(). Before the expiration, updated objects may still
remain in the session with stale values on their attributes, which
can lead to confusing results.
-
+
'fetch' - performs a select query before the update to find
objects that are matched by the update query. The updated
attributes are expired on matched objects.
@@ -2254,7 +2254,7 @@ class Query(object):
"the synchronize_session argument of "
"query.update() is now called 'fetch'")
synchronize_session = 'fetch'
-
+
if synchronize_session not in [False, 'evaluate', 'fetch']:
raise sa_exc.ArgumentError(
"Valid strategies for session synchronization "
@@ -2342,7 +2342,7 @@ class Query(object):
session.identity_map[identity_key],
[_attr_as_key(k) for k in values]
)
-
+
session.dispatch.after_bulk_update(session, self, context, result)
return result.rowcount
@@ -2367,21 +2367,21 @@ class Query(object):
for entity in self._entities:
entity.setup_context(self, context)
-
+
for rec in context.create_eager_joins:
strategy = rec[0]
strategy(*rec[1:])
-
+
eager_joins = context.eager_joins.values()
if context.from_clause:
# "load from explicit FROMs" mode,
# i.e. when select_from() or join() is used
- froms = list(context.from_clause)
+ froms = list(context.from_clause)
else:
# "load from discrete FROMs" mode,
# i.e. when each _MappedEntity has its own FROM
- froms = context.froms
+ froms = context.froms
if self._enable_single_crit:
self._adjust_for_single_inheritance(context)
@@ -2422,10 +2422,10 @@ class Query(object):
order_by=context.order_by,
**self._select_args
)
-
+
for hint in self._with_hints:
inner = inner.with_hint(*hint)
-
+
if self._correlate:
inner = inner.correlate(*self._correlate)
@@ -2439,7 +2439,7 @@ class Query(object):
[inner] + context.secondary_columns,
for_update=for_update,
use_labels=labels)
-
+
if self._execution_options:
statement = statement.execution_options(
**self._execution_options)
@@ -2492,7 +2492,7 @@ class Query(object):
for hint in self._with_hints:
statement = statement.with_hint(*hint)
-
+
if self._execution_options:
statement = statement.execution_options(
**self._execution_options)
@@ -2516,7 +2516,7 @@ class Query(object):
selected from the total results.
"""
-
+
for entity, (mapper, adapter, s, i, w) in \
self._mapper_adapter_map.iteritems():
single_crit = mapper._single_table_criterion
@@ -2558,7 +2558,7 @@ class _MapperEntity(_QueryEntity):
self.entities = [entity]
self.entity_zero = self.expr = entity
-
+
def setup_entity(self, entity, mapper, adapter,
from_obj, is_aliased_class, with_polymorphic):
self.mapper = mapper
@@ -2578,8 +2578,8 @@ class _MapperEntity(_QueryEntity):
self._reduced_path = (mapper.base_mapper, )
self.entity_zero = mapper
self._label_name = self.mapper.class_.__name__
-
-
+
+
def set_with_polymorphic(self, query, cls_or_mappers,
selectable, discriminator):
if cls_or_mappers is None:
@@ -2611,14 +2611,14 @@ class _MapperEntity(_QueryEntity):
query._entities.append(self)
def _get_entity_clauses(self, query, context):
-
+
adapter = None
if not self.is_aliased_class and query._polymorphic_adapters:
adapter = query._polymorphic_adapters.get(self.mapper, None)
if not adapter and self.adapter:
adapter = self.adapter
-
+
if adapter:
if query._from_obj_alias:
ret = adapter.wrap(query._from_obj_alias)
@@ -2666,7 +2666,7 @@ class _MapperEntity(_QueryEntity):
self._polymorphic_discriminator)
return _instance, self._label_name
-
+
def setup_context(self, query, context):
adapter = self._get_entity_clauses(query, context)
@@ -2688,7 +2688,7 @@ class _MapperEntity(_QueryEntity):
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:
@@ -2718,7 +2718,7 @@ class _ColumnEntity(_QueryEntity):
def __init__(self, query, column):
self.expr = column
-
+
if isinstance(column, basestring):
column = sql.literal_column(column)
self._label_name = column.name
@@ -2779,17 +2779,17 @@ class _ColumnEntity(_QueryEntity):
self.entity_zero = list(self.entities)[0]
else:
self.entity_zero = None
-
+
@property
def type(self):
return self.column.type
-
+
def adapt_to_selectable(self, query, sel):
c = _ColumnEntity(query, sel.corresponding_column(self.column))
c._label_name = self._label_name
c.entity_zero = self.entity_zero
c.entities = self.entities
-
+
def setup_entity(self, entity, mapper, adapter, from_obj,
is_aliased_class, with_polymorphic):
self.selectable = from_obj
@@ -2834,7 +2834,7 @@ class QueryContext(object):
multi_row_eager_loaders = False
adapter = None
froms = ()
-
+
def __init__(self, query):
if query._statement is not None: