Mike Bayer avatar Mike Bayer committed 99564ce

- [bug] Fixed bug whereby hybrid_property didn't
work as a kw arg in any(), has().

Comments (0)

Files changed (3)

 =======
 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

lib/sqlalchemy/orm/properties.py

                         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:

test/ext/test_hybrid.py

-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
         class A(Base):
             __tablename__ = 'a'
             id = Column(Integer, primary_key=True)
+
             _value = Column("value", String)
 
             @hybrid.hybrid_property
 
         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)
             "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(
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.