Commits

Mike Bayer committed 13cdc68

move factory function to classmethod

Comments (0)

Files changed (2)

lib/sqlalchemy/orm/dependency.py

 from sqlalchemy.orm import attributes, exc, sync, unitofwork, util as mapperutil
 from sqlalchemy.orm.interfaces import ONETOMANY, MANYTOONE, MANYTOMANY
 
-
-def create_dependency_processor(prop):
-    types = {
-        ONETOMANY : OneToManyDP,
-        MANYTOONE: ManyToOneDP,
-        MANYTOMANY : ManyToManyDP,
-    }
-    return types[prop.direction](prop)
-
 class DependencyProcessor(object):
     def __init__(self, prop):
         self.prop = prop
                     "No target attributes to populate between parent and "
                     "child are present" %
                      self.prop)
-
+    
+    @classmethod
+    def from_relationship(cls, prop):
+        return _direction_to_processor[prop.direction](prop)
+        
     def hasparent(self, state):
         """return True if the given object instance has a parent,
         according to the ``InstrumentedAttribute`` handled by this 
                             self.parent, 
                             self.prop.synchronize_pairs)
 
+_direction_to_processor = {
+    ONETOMANY : OneToManyDP,
+    MANYTOONE: ManyToOneDP,
+    MANYTOMANY : ManyToManyDP,
+}
+

lib/sqlalchemy/orm/properties.py

             self.uselist = self.direction is not MANYTOONE
 
         if not self.viewonly:
-            self._dependency_processor = dependency.create_dependency_processor(self)
+            self._dependency_processor = \
+                        dependency.DependencyProcessor.from_relationship(self)
     
     @util.memoized_property
     def _use_get(self):