From 2d7cc7f996579703baac12ff97995465f0e06091 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 11 Apr 2010 12:21:36 -0400 Subject: move factory function to classmethod --- lib/sqlalchemy/orm/dependency.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/sqlalchemy/orm/dependency.py') diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index b84794699..731b21549 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, +} + -- cgit v1.2.1