]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Adjusted dictlike-polymorphic.py example
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Sep 2011 21:22:52 +0000 (17:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 26 Sep 2011 21:22:52 +0000 (17:22 -0400)
    to apply the CAST such that it works on
    PG, other databases.  [ticket:2266]

CHANGES
examples/vertical/dictlike-polymorphic.py

diff --git a/CHANGES b/CHANGES
index cc30f03c0d3135a41aa2ccc971eac7d154535ced..229f50bffd49b4618b421d9e1799a863d2903594 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -270,6 +270,12 @@ CHANGES
     dictionary that had tuples as keys would be misinterpreted
     as a sequence. [ticket:2275]
 
+- examples
+  - Adjusted dictlike-polymorphic.py example
+    to apply the CAST such that it works on 
+    PG, other databases.  [ticket:2266]
+    Also in 0.6.9.
+
 0.7.2
 =====
 - orm
index d66b1872f33a7fd6ff697820cfff43aeaa0c06b2..c4eb6b5ce620ebe8776826c02f898b570227d977 100644 (file)
@@ -113,14 +113,14 @@ class PolymorphicVerticalProperty(object):
             self.cls = cls
 
         def _case(self):
-            whens = [(text("'%s'" % p[0]), getattr(self.cls, p[1]))
+            whens = [(text("'%s'" % p[0]), cast(getattr(self.cls, p[1]), String))
                      for p in self.cls.type_map.values()
                      if p[1] is not None]
             return case(whens, self.cls.type, null())
         def __eq__(self, other):
-            return cast(self._case(), String) == cast(other, String)
+            return self._case() == cast(other, String)
         def __ne__(self, other):
-            return cast(self._case(), String) != cast(other, String)
+            return self._case() != cast(other, String)
 
     def __repr__(self):
         return '<%s %r=%r>' % (self.__class__.__name__, self.key, self.value)
@@ -185,9 +185,10 @@ if __name__ == '__main__':
 
     mapper(AnimalFact, chars)
 
-    metadata.bind = create_engine('sqlite://', echo=True)
-    metadata.create_all()
-    session = Session()
+    engine = create_engine('sqlite://', echo=True)
+
+    metadata.create_all(engine)
+    session = Session(engine)
 
     stoat = Animal(u'stoat')
     stoat[u'color'] = u'red'
@@ -254,5 +255,5 @@ if __name__ == '__main__':
          filter(with_characteristic(u'cuteness', u'very cute')))
     print q.all()
 
-
-    metadata.drop_all()
+    session.close()
+    metadata.drop_all(engine)