]> 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:46:52 +0000 (14:46 -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

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 65c72e5e1d8d5c773e5845506038c5e415c843af..c6fdf479ed3d12b311dbb3868cc8fb6c597c4ce3 100644 (file)
@@ -2558,18 +2558,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
                 }
             ]
 
@@ -2579,7 +2582,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 84ebf393ec19e06939bc789e0467d4d54e324f42..fc9e6e3afe335c5e47f96fbab80d476e14c6fda8 100644 (file)
@@ -79,17 +79,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}
                 ]
             ),
             (
@@ -97,10 +97,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}
                 ]
             ),
             (
@@ -108,7 +108,7 @@ class RowTupleTest(QueryTest):
                 [
                     {
                         'name': 'aalias', 'type': Address, 'aliased': True,
-                        'expr': address_alias}
+                        'expr': address_alias, 'entity': address_alias}
                 ]
             ),
             (
@@ -116,19 +116,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
+                    }
                 ]
             )
         ]: