]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
move factory function to classmethod
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Apr 2010 16:21:36 +0000 (12:21 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Apr 2010 16:21:36 +0000 (12:21 -0400)
lib/sqlalchemy/orm/dependency.py
lib/sqlalchemy/orm/properties.py

index b8479469938a6f27fef566143fea1178cfc09639..731b21549c97755dba3f06539a2959a97f44d9e7 100644 (file)
@@ -13,15 +13,6 @@ import sqlalchemy.exceptions as sa_exc
 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
@@ -41,7 +32,11 @@ class DependencyProcessor(object):
                     "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 
@@ -1010,3 +1005,9 @@ class ManyToManyDP(DependencyProcessor):
                             self.parent, 
                             self.prop.synchronize_pairs)
 
+_direction_to_processor = {
+    ONETOMANY : OneToManyDP,
+    MANYTOONE: ManyToOneDP,
+    MANYTOMANY : ManyToManyDP,
+}
+
index 8f9cb85251ca16697e0a554b35c1759771e069d8..41a8877bfaf1a2d9a036597c26c76a201e7eb7ec 100644 (file)
@@ -1194,7 +1194,8 @@ class RelationshipProperty(StrategizedProperty):
             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):