From f54a3b255a5f93b44b7530d89f6d17e3938150f4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 11 Jan 2012 16:35:34 -0500 Subject: add examples for multi metadata under __abstract__, custom vertical partitioning --- lib/sqlalchemy/ext/declarative.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/sqlalchemy/ext') diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 61ec53343..bd655a721 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -906,6 +906,7 @@ has finished:: "" # do something with mappings +.. _declarative_abstract: ``__abstract__`` ~~~~~~~~~~~~~~~~~~~ @@ -927,6 +928,26 @@ just from the special class:: class MyMappedClass(SomeAbstractBase): "" + +One possible use of ``__abstract__`` is to use a distinct :class:`.MetaData` for different +bases:: + + Base = declarative_base() + + class DefaultBase(Base): + __abstract__ = True + metadata = MetaData() + + class OtherBase(Base): + __abstract__ = True + metadata = MetaData() + +Above, classes which inherit from ``DefaultBase`` will use one :class:`.MetaData` as the +registry of tables, and those which inherit from ``OtherBase`` will use a different one. +The tables themselves can then be created perhaps within distinct databases:: + + DefaultBase.metadata.create_all(some_engine) + OtherBase.metadata_create_all(some_other_engine) Class Constructor ================= -- cgit v1.2.1