]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- the _make_proxy() method of ColumnClause and Column now use
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 May 2010 15:37:48 +0000 (11:37 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 10 May 2010 15:37:48 +0000 (11:37 -0400)
self.__class__ to determine the class of object to be returned
instead of hardcoding to ColumnClause/Column, making it slightly
easier to produce specific subclasses of these which work in
alias/subquery situations.

CHANGES
lib/sqlalchemy/schema.py
lib/sqlalchemy/sql/expression.py
lib/sqlalchemy/sql/util.py

diff --git a/CHANGES b/CHANGES
index 39326b491f4b26e9affef5745515de9d694c7169..3438fab4f6f26e9f65ee970d63c6c5a84626fcd5 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,7 +31,13 @@ CHANGES
   - Fixed bug in connection pool cursor wrapper whereby if a
     cursor threw an exception on close(), the logging of the 
     message would fail.  [ticket:1786]
-    
+
+  - the _make_proxy() method of ColumnClause and Column now use
+    self.__class__ to determine the class of object to be returned
+    instead of hardcoding to ColumnClause/Column, making it slightly 
+    easier to produce specific subclasses of these which work in 
+    alias/subquery situations.
+
 - engines
   - Fixed building the C extensions on Python 2.4. [ticket:1781]
 
index 7a12891804c56e4ce032b7ef5582835857bec904..168296db61ac699df9b6ea853c5f06bf205b6dee 100644 (file)
@@ -855,7 +855,7 @@ class Column(SchemaItem, expression.ColumnClause):
         
         """
         fk = [ForeignKey(f.column) for f in self.foreign_keys]
-        c = Column(
+        c = self._constructor(
             name or self.name, 
             self.type, 
             key = name or self.key, 
index 440c118333b04f0ea9e882b2ee857db55f0bab62..9ac5c1d66d9f04fe1be081e8f9181519e5618798 100644 (file)
@@ -1037,6 +1037,18 @@ class ClauseElement(Visitable):
 
         return c
 
+    @property
+    def _constructor(self):
+        """return the 'constructor' for this ClauseElement.
+        
+        This is for the purposes for creating a new object of 
+        this type.   Usually, its just the element's __class__.  
+        However, the "Annotated" version of the object overrides
+        to return the class of its proxied element.
+
+        """
+        return self.__class__
+
     @util.memoized_property
     def _cloned_set(self):
         """Return the set consisting all cloned anscestors of this
@@ -3244,7 +3256,7 @@ class ColumnClause(_Immutable, ColumnElement):
         # propagate the "is_literal" flag only if we are keeping our name,
         # otherwise its considered to be a label
         is_literal = self.is_literal and (name is None or name == self.name)
-        c = ColumnClause(
+        c = self._constructor(
                     name or self.name, 
                     selectable=selectable, 
                     type_=self.type, 
index b81906396f067a134c574fa980e47316e1471dbb..e4ebe953844580f4040a6cc420b99b972bd90461 100644 (file)
@@ -265,6 +265,10 @@ class Annotated(object):
     
     def _deannotate(self):
         return self.__element
+
+    @property
+    def _constructor(self):
+        return self.__element.__class__
         
     def _clone(self):
         clone = self.__element._clone()