[Checkins] SVN: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/ fix for
dealing with custom mappers
Andreas Jung
andreas at andreas-jung.com
Mon Apr 23 04:55:22 EDT 2007
Log message for revision 74653:
fix for dealing with custom mappers
Changed:
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
U z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/mapper.py
-=-
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt 2007-04-23 08:06:15 UTC (rev 74652)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/CHANGES.txt 2007-04-23 08:55:21 UTC (rev 74653)
@@ -1,8 +1,11 @@
-0.1.8 (unreleased)
+0.1.8 (23.04.2007)
- added shorter method names as aliases
+ - don't generate a new mapper class if a custom mapper
+ class is defined within the model
+
0.1.7 (21.04.2007)
- replaced 'echo' parameter of the constructor with a generic **kw
Modified: z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/mapper.py
===================================================================
--- z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/mapper.py 2007-04-23 08:06:15 UTC (rev 74652)
+++ z3c.sqlalchemy/trunk/src/z3c/sqlalchemy/mapper.py 2007-04-23 08:55:21 UTC (rev 74653)
@@ -22,6 +22,8 @@
class MappedClassBase(object):
""" base class for all mapped classes """
+ __auto_mapped__ = False
+
def __init__(self, **kw):
""" accepts keywords arguments used for initialization of
mapped attributes/columns.
@@ -53,6 +55,7 @@
newCls = cls
mapper(newCls, table, properties=properties)
+ newCls.__auto_mapped__ = True
return newCls
@@ -101,8 +104,10 @@
# check if the model contains an optional mapper class
mapper_class = None
- if self._model.has_key(name):
+ auto_mapped = False
+ if self._model.has_key(name):
mapper_class = self._model[name].get('mapper_class')
+ auto_mapped = getattr(mapper_class, '__auto_mapped__', False)
# use auto-introspected table dependencies for creating
@@ -140,9 +145,15 @@
properties[table_refname] = relation(table_ref_mapper)
# create a mapper and cache it
- mapper = self._mapper_factory(table,
- properties=properties,
- cls=mapper_class)
+
+
+ if mapper_class.__dict__.has_key('c'):
+ mapper = mapper_class
+
+ else:
+ mapper = self._mapper_factory(table,
+ properties=properties,
+ cls=mapper_class)
self._registerMapper(mapper, name)
return self[name]
More information about the Checkins
mailing list