From: Mike Bayer Date: Sun, 11 Apr 2010 16:21:36 +0000 (-0400) Subject: move factory function to classmethod X-Git-Tag: rel_0_6_0~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d7cc7f996579703baac12ff97995465f0e06091;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git move factory function to classmethod --- diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index b847946993..731b21549c 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -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, +} + diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 8f9cb85251..41a8877bfa 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -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):