summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-10-04 15:22:43 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-10-04 15:22:43 -0400
commitaba78471867d1ae2cfbbf358482b2a9b771cc6b0 (patch)
tree4ad6eb524b6c56c9245440a2a146f3e9649601c3
parenta83378b64005971fe97dff270641bce4967dbb53 (diff)
downloadsqlalchemy-aba78471867d1ae2cfbbf358482b2a9b771cc6b0.tar.gz
fix entity_zero resolution
-rw-r--r--lib/sqlalchemy/orm/query.py11
-rw-r--r--test/orm/test_bundle.py13
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index c3e5aa10d..beabc5811 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -3194,7 +3194,7 @@ class Bundle(object):
class _BundleEntity(_QueryEntity):
def __init__(self, query, bundle, setup_entities=True):
query._entities.append(self)
- self.bundle = self.entity_zero = bundle
+ self.bundle = bundle
self.type = type(bundle)
self._label_name = bundle.name
self._entities = []
@@ -3210,6 +3210,15 @@ class _BundleEntity(_QueryEntity):
self.filter_fn = lambda item: item
+ @property
+ def entity_zero(self):
+ for ent in self._entities:
+ ezero = ent.entity_zero
+ if ezero is not None:
+ return ezero
+ else:
+ return None
+
def corresponds_to(self, entity):
# TODO: this seems to have no effect for
# _ColumnEntity either
diff --git a/test/orm/test_bundle.py b/test/orm/test_bundle.py
index 305f8d3c6..1a60cc685 100644
--- a/test/orm/test_bundle.py
+++ b/test/orm/test_bundle.py
@@ -224,6 +224,19 @@ class BundleTest(fixtures.MappedTest, AssertsCompiledSQL):
((9, 'd8d1', 'd8d2'),), ((10, 'd9d1', 'd9d2'),)]
)
+ def test_filter_by(self):
+ Data = self.classes.Data
+
+ b1 = Bundle('b1', Data.id, Data.d1, Data.d2)
+
+ sess = Session()
+
+ self.assert_compile(
+ sess.query(b1).filter_by(d1='d1'),
+ "SELECT data.id AS data_id, data.d1 AS data_d1, "
+ "data.d2 AS data_d2 FROM data WHERE data.d1 = :d1_1"
+ )
+
def test_clause_expansion(self):
Data = self.classes.Data