]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] Fixed bug whereby hybrid_property didn't
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Dec 2011 15:41:33 +0000 (10:41 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Dec 2011 15:41:33 +0000 (10:41 -0500)
    work as a kw arg in any(), has().

CHANGES
lib/sqlalchemy/orm/properties.py
test/ext/test_hybrid.py

diff --git a/CHANGES b/CHANGES
index 0a2029a3db684114a51774979f649141f98a266b..2b4959e9079ad33bc28835e651f802c0bef5c20a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,12 @@
 =======
 CHANGES
 =======
+0.7.5
+=====
+- orm
+  - [bug] Fixed bug whereby hybrid_property didn't 
+    work as a kw arg in any(), has().
+
 0.7.4
 =====
 - orm
index 8794cd3dadd637e43d6b9d38c8d8a299e2130743..40032c9497caeef4fb03c1687ab82ad026fc77b8 100644 (file)
@@ -428,7 +428,7 @@ class RelationshipProperty(StrategizedProperty):
                         source_selectable=source_selectable)
 
             for k in kwargs:
-                crit = self.property.mapper.class_manager[k] == kwargs[k]
+                crit = getattr(self.property.mapper.class_, k) == kwargs[k]
                 if criterion is None:
                     criterion = crit
                 else:
index 649b796f7244c59ad76a2c12ca95f3543eb9c161..7ed8e207c3b42786e1a4bac4093e940ddc168f56 100644 (file)
@@ -1,4 +1,4 @@
-from sqlalchemy import func, Integer, String
+from sqlalchemy import func, Integer, String, ForeignKey
 from sqlalchemy.orm import relationship, Session, aliased
 from test.lib.schema import Column
 from sqlalchemy.ext.declarative import declarative_base
@@ -23,6 +23,7 @@ class PropertyComparatorTest(fixtures.TestBase, AssertsCompiledSQL):
         class A(Base):
             __tablename__ = 'a'
             id = Column(Integer, primary_key=True)
+
             _value = Column("value", String)
 
             @hybrid.hybrid_property
@@ -106,6 +107,39 @@ class PropertyExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
 
         return A
 
+    def _relationship_fixture(self):
+        Base = declarative_base()
+
+        class A(Base):
+            __tablename__ = 'a'
+            id = Column(Integer, primary_key=True)
+            b_id = Column('bid', Integer, ForeignKey('b.id'))
+            _value = Column("value", String)
+
+            @hybrid.hybrid_property
+            def value(self):
+                return int(self._value) - 5
+
+            @value.expression
+            def value(cls):
+                return func.foo(cls._value) + cls.bar_value
+
+            @value.setter
+            def value(self, v):
+                self._value = v + 5
+
+            @hybrid.hybrid_property
+            def bar_value(cls):
+                return func.bar(cls._value)
+
+        class B(Base):
+            __tablename__ = 'b'
+            id = Column(Integer, primary_key=True)
+
+            as_ = relationship("A")
+
+        return A, B
+
     def test_set_get(self):
         A = self._fixture()
         a1 = A(value=5)
@@ -119,6 +153,17 @@ class PropertyExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
             "foo(a.value) + bar(a.value)"
         )
 
+    def test_any(self):
+        A, B = self._relationship_fixture()
+        sess = Session()
+        self.assert_compile(
+            sess.query(B).filter(B.as_.any(value=5)),
+            "SELECT b.id AS b_id FROM b WHERE EXISTS "
+            "(SELECT 1 FROM a WHERE b.id = a.bid "
+            "AND foo(a.value) + bar(a.value) = :param_1)"
+        )
+
+
     def test_aliased_expression(self):
         A = self._fixture()
         self.assert_compile(