From: Mike Bayer Date: Wed, 11 Mar 2015 18:46:52 +0000 (-0400) Subject: - Added a new entry ``"entity"`` to the dictionaries returned by X-Git-Tag: rel_1_0_0b1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b815e9483319b93f98bef11c7d47378441f78d21;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. references #3320 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index c6398b1bcb..d6439cc1ee 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -11,6 +11,20 @@ .. 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 diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 65c72e5e1d..c6fdf479ed 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -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 ] diff --git a/test/orm/test_query.py b/test/orm/test_query.py index 84ebf393ec..fc9e6e3afe 100644 --- a/test/orm/test_query.py +++ b/test/orm/test_query.py @@ -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 + } ] ) ]: