diff options
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/loading.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 32 |
2 files changed, 30 insertions, 8 deletions
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 8de7d5a8b..25ba8a398 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -42,11 +42,7 @@ def instances(query, cursor, context): filtered = query._has_mapper_entities - single_entity = ( - not query._only_return_tuples - and len(query._entities) == 1 - and query._entities[0].supports_single_entity - ) + single_entity = query.is_single_entity if filtered: if single_entity: diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 92f9ee952..1a36349f3 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -640,14 +640,40 @@ class Query(Generative): @_generative def only_return_tuples(self, value): - """When set to True, the query results will always be a tuple, - specifically for single element queries. The default is False. + """When set to True, the query results will always be a tuple. - . .. versionadded:: 1.2.5 + This is specifically for single element queries. The default is False. + + .. versionadded:: 1.2.5 + + .. seealso:: + + :meth:`.Query.is_single_entity` """ self._only_return_tuples = value + @property + def is_single_entity(self): + """Indicates if this :class:`.Query` returns tuples or single entities. + + Returns True if this query returns a single entity for each instance + in its result list, and False if this query returns a tuple of entities + for each result. + + .. versionadded:: 1.3.11 + + .. seealso:: + + :meth:`.Query.only_return_tuples` + + """ + return ( + not self._only_return_tuples + and len(self._entities) == 1 + and self._entities[0].supports_single_entity + ) + @_generative def enable_eagerloads(self, value): """Control whether or not eager joins and subqueries are |
