]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix entity_zero resolution
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Oct 2013 19:22:43 +0000 (15:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Oct 2013 19:22:43 +0000 (15:22 -0400)
lib/sqlalchemy/orm/query.py
test/orm/test_bundle.py

index c3e5aa10d37f44c71151b64ae2004748850bffb0..beabc5811827ee7d3dd212e77c28588013e39211 100644 (file)
@@ -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
index 305f8d3c6961bc4b2f492470c98127dee6538762..1a60cc685bc6006707f9c606d9a1894e422a40a8 100644 (file)
@@ -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