Commits

Mike Bayer committed ccc9980

- Merged 0.5's declarative behavior such that all
Column and MapperProperty objects keep a state
variable indicating their creation order, which
declarative_base() maintains when generating
Table constructs.

Comments (0)

Files changed (5)

       which fulfills NUMERIC affinity, but that's not the 
       same as REAL.
 
+- extensions
+    - Merged 0.5's declarative behavior such that all 
+      Column and MapperProperty objects keep a state
+      variable indicating their creation order, which 
+      declarative_base() maintains when generating
+      Table constructs.
+      
 0.4.6
 =====
 - orm

lib/sqlalchemy/ext/declarative.py

             prop = _deferred_relation(cls, value)
             our_stuff[k] = prop
 
+        # set up attributes in the order they were created 
+        our_stuff.sort(lambda x, y: cmp(our_stuff[x]._creation_order, our_stuff[y]._creation_order))
+
         table = None
         if '__table__' not in cls.__dict__:
             if '__tablename__' in cls.__dict__:

lib/sqlalchemy/orm/properties.py

         self.group = kwargs.pop('group', None)
         self.deferred = kwargs.pop('deferred', False)
         self.comparator = ColumnProperty.ColumnComparator(self)
+        util.set_creation_order(self)
+        
         if self.deferred:
             self.strategy_class = strategies.DeferredColumnLoader
         else:
         self.name = name
         self.map_column=map_column
         self.descriptor = descriptor
+        util.set_creation_order(self)
 
     def setup(self, querycontext, **kwargs):
         pass
     def __init__(self, comparator_factory, descriptor=None):
         self.descriptor = descriptor
         self.comparator = comparator_factory(self)
-
+        util.set_creation_order(self)
+        
     def do_init(self):
         """Set up a proxy to the unmanaged descriptor."""
 
         self.comparator = PropertyLoader.Comparator(self)
         self.join_depth = join_depth
         self._arg_local_remote_pairs = _local_remote_pairs
+        util.set_creation_order(self)
         
         if strategy_class:
             self.strategy_class = strategy_class

lib/sqlalchemy/schema.py

         self.autoincrement = kwargs.pop('autoincrement', True)
         self.constraints = util.Set()
         self.foreign_keys = util.OrderedSet()
+        util.set_creation_order(self)
         if kwargs.get('info'):
             self._info = kwargs.pop('info')
         if kwargs:

lib/sqlalchemy/util.py

         self._list = []
         dict.clear(self)
 
+    def sort(self, fn=None):
+        self._list.sort(fn)
+            
     def update(self, ____sequence=None, **kwargs):
         if ____sequence is not None:
             if hasattr(____sequence, 'keys'):
                           fn.func_defaults, fn.func_closure)
     return fn
 
+
+_creation_order = 1 
+def set_creation_order(instance): 
+    """assign a '_creation_order' sequence to the given instance. 
+ 
+    This allows multiple instances to be sorted in order of 
+    creation (typically within a single thread; the counter is 
+    not particularly threadsafe). 
+
+    """ 
+    global _creation_order 
+    instance._creation_order = _creation_order 
+    _creation_order +=1
+
 def conditional_cache_decorator(func):
     """apply conditional caching to the return value of a function."""
 
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.