summaryrefslogtreecommitdiff
path: root/examples/generic_associations/table_per_association.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/generic_associations/table_per_association.py')
-rw-r--r--examples/generic_associations/table_per_association.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/examples/generic_associations/table_per_association.py b/examples/generic_associations/table_per_association.py
index 84e85de2f..4993492a4 100644
--- a/examples/generic_associations/table_per_association.py
+++ b/examples/generic_associations/table_per_association.py
@@ -1,8 +1,9 @@
"""table_per_association.py
-The HasAddresses mixin will provide a new "address_association" table for
-each parent class. The "address" table will be shared
-for all parents.
+Illustrates a mixin which provides a generic association
+via a individually generated association tables for each parent class.
+The associated objects themselves are persisted in a single table
+shared among all parents.
This configuration has the advantage that all Address
rows are in one table, so that the definition of "Address"
@@ -12,11 +13,12 @@ has no dependency on the system.
"""
-from sqlalchemy.ext.declarative import declarative_base, declared_attr
+from sqlalchemy.ext.declarative import as_declarative, declared_attr
from sqlalchemy import create_engine, Integer, Column, \
String, ForeignKey, Table
from sqlalchemy.orm import Session, relationship
+@as_declarative()
class Base(object):
"""Base class which provides automated table name
and surrogate primary key column.
@@ -26,7 +28,6 @@ class Base(object):
def __tablename__(cls):
return cls.__name__.lower()
id = Column(Integer, primary_key=True)
-Base = declarative_base(cls=Base)
class Address(Base):
"""The Address class.