diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-12-28 11:10:49 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-12-28 11:10:49 -0500 |
commit | 7f07d43fb127a2b2283a7d17a714ed175498b6b9 (patch) | |
tree | f69dce8ecbe5902b32f3d8bde4ec9c9ba367cb41 /lib/sqlalchemy/ext/declarative.py | |
parent | 45e3b4d0c56321890c52e69f6eb36868ab3c2173 (diff) | |
download | sqlalchemy-7f07d43fb127a2b2283a7d17a714ed175498b6b9.tar.gz |
- [feature] Added "class_registry" argument to
declarative_base(). Allows two or more declarative
bases to share the same registry of class names.
Diffstat (limited to 'lib/sqlalchemy/ext/declarative.py')
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 91d770197..dc84c5dfb 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -1500,6 +1500,7 @@ _declarative_constructor.__name__ = '__init__' def declarative_base(bind=None, metadata=None, mapper=None, cls=object, name='Base', constructor=_declarative_constructor, + class_registry=None, metaclass=DeclarativeMeta): """Construct a base class for declarative class definitions. @@ -1543,6 +1544,13 @@ def declarative_base(bind=None, metadata=None, mapper=None, cls=object, no __init__ will be provided and construction will fall back to cls.__init__ by way of the normal Python semantics. + :param class_registry: optional dictionary that will serve as the + registry of class names-> mapped classes when string names + are used to identify classes inside of :func:`.relationship` + and others. Allows two or more declarative base classes + to share the same registry of class names for simplified + inter-base relationships. + :param metaclass: Defaults to :class:`.DeclarativeMeta`. A metaclass or __metaclass__ compatible callable to use as the meta type of the generated @@ -1553,8 +1561,11 @@ def declarative_base(bind=None, metadata=None, mapper=None, cls=object, if bind: lcl_metadata.bind = bind + if class_registry is None: + class_registry = {} + bases = not isinstance(cls, tuple) and (cls,) or cls - class_dict = dict(_decl_class_registry=dict(), + class_dict = dict(_decl_class_registry=class_registry, metadata=lcl_metadata) if constructor: |