]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added a new entry ``"entity"`` to the dictionaries returned by
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Mar 2015 18:46:52 +0000 (14:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 11 Mar 2015 18:47:21 +0000 (14:47 -0400)
:attr:`.Query.column_descriptions`.  This refers to the primary ORM
mapped class or aliased class that is referred to by the expression.
Compared to the existing entry for ``"type"``, it will always be
a mapped entity, even if extracted from a column expression, or
None if the given expression is a pure core expression.
references #3320

(cherry picked from commit b815e9483319b93f98bef11c7d47378441f78d21)

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/orm/query.py
test/orm/test_query.py

index c6398b1bcb17871b2742ce04a82bb186f47ce05b..d6439cc1ee2c8d79bab92055c527b23e7435716e 100644 (file)
     .. include:: changelog_07.rst
         :start-line: 5
 
+.. changelog::
+    :version: 0.9.10
+
+    .. change::
+        :tags: feature, orm
+        :tickets: 3320
+
+        Added a new entry ``"entity"`` to the dictionaries returned by
+        :attr:`.Query.column_descriptions`.  This refers to the primary ORM
+        mapped class or aliased class that is referred to by the expression.
+        Compared to the existing entry for ``"type"``, it will always be
+        a mapped entity, even if extracted from a column expression, or
+        None if the given expression is a pure core expression.
+
 .. changelog::
     :version: 0.9.9
     :released: March 10, 2015
index ce16df004c00fc95ab7f65e8d7efb8d99e7f62e5..b927db60abf33fbc50323592cc870a81f6c1ba52 100644 (file)
@@ -2476,18 +2476,21 @@ class Query(object):
                     'type':User,
                     'aliased':False,
                     'expr':User,
+                    'entity': User
                 },
                 {
                     'name':'id',
                     'type':Integer(),
                     'aliased':False,
                     'expr':User.id,
+                    'entity': User
                 },
                 {
                     'name':'user2',
                     'type':User,
                     'aliased':True,
-                    'expr':user_alias
+                    'expr':user_alias,
+                    'entity': user_alias
                 }
             ]
 
@@ -2497,7 +2500,10 @@ class Query(object):
                 'name': ent._label_name,
                 'type': ent.type,
                 'aliased': getattr(ent, 'is_aliased_class', False),
-                'expr': ent.expr
+                'expr': ent.expr,
+                'entity':
+                    ent.entity_zero.entity if ent.entity_zero is not None
+                    else None
             }
             for ent in self._entities
         ]
index 940b17aaf45fd227db6f67d1283ea94cf90b7687..74b9c2956b8b17fb04bbb7eac32097c6d8f67b94 100644 (file)
@@ -74,17 +74,17 @@ class RowTupleTest(QueryTest):
                 [
                     {
                         'name': 'User', 'type': User, 'aliased': False,
-                        'expr': User}]
+                        'expr': User, 'entity': User}]
             ),
             (
                 sess.query(User.id, User),
                 [
                     {
                         'name': 'id', 'type': users.c.id.type,
-                        'aliased': False, 'expr': User.id},
+                        'aliased': False, 'expr': User.id, 'entity': User},
                     {
                         'name': 'User', 'type': User, 'aliased': False,
-                        'expr': User}
+                        'expr': User, 'entity': User}
                 ]
             ),
             (
@@ -92,10 +92,10 @@ class RowTupleTest(QueryTest):
                 [
                     {
                         'name': 'id', 'type': users.c.id.type,
-                        'aliased': False, 'expr': User.id},
+                        'aliased': False, 'expr': User.id, 'entity': User},
                     {
                         'name': None, 'type': User, 'aliased': True,
-                        'expr': user_alias}
+                        'expr': user_alias, 'entity': user_alias}
                 ]
             ),
             (
@@ -103,7 +103,7 @@ class RowTupleTest(QueryTest):
                 [
                     {
                         'name': 'aalias', 'type': Address, 'aliased': True,
-                        'expr': address_alias}
+                        'expr': address_alias, 'entity': address_alias}
                 ]
             ),
             (
@@ -111,19 +111,28 @@ class RowTupleTest(QueryTest):
                 [
                     {
                         'name': 'uname', 'type': users.c.name.type,
-                        'aliased': False, 'expr': name_label},
+                        'aliased': False, 'expr': name_label, 'entity': User},
                     {
                         'name': None, 'type': fn.type, 'aliased': False,
-                        'expr': fn},
+                        'expr': fn, 'entity': User},
                 ]
             ),
+            (
+                sess.query(users.c.name),
+                [{
+                    "name": "name", "type": users.c.name.type,
+                    "aliased": False, "expr": users.c.name, "entity": None
+                }]
+            ),
             (
                 sess.query(bundle),
                 [
-                    {'aliased': False,
-                    'expr': bundle,
-                    'type': Bundle,
-                    'name': 'b1'}
+                    {
+                        'aliased': False,
+                        'expr': bundle,
+                        'type': Bundle,
+                        'name': 'b1', 'entity': User
+                    }
                 ]
             )
         ]: