Commits

Mike Bayer  committed 4e8b9e6

patch to inheritance section

  • Participants
  • Parent commits 7adf5b7

Comments (0)

Files changed (1)

File doc/build/content/adv_datamapping.txt

 Like concrete table inheritance, this can be done non-polymorphically, or with a little more complexity, polymorphically:
 
     {python title="Multiple Table Inheritance, Non-polymorphic"}
-    people = Table('people', metadata, 
+    employees = Table('employees', metadata, 
        Column('person_id', Integer, primary_key=True),
        Column('name', String(50)),
        Column('type', String(30)))
 
     engineers = Table('engineers', metadata, 
-       Column('person_id', Integer, ForeignKey('people.person_id'), primary_key=True),
+       Column('person_id', Integer, ForeignKey('employees.person_id'), primary_key=True),
        Column('engineer_info', String(50)),
       )
 
     managers = Table('managers', metadata, 
-       Column('person_id', Integer, ForeignKey('people.person_id'), primary_key=True),
+       Column('person_id', Integer, ForeignKey('employees.person_id'), primary_key=True),
        Column('manager_data', String(50)),
        )
 
-    person_mapper = mapper(Person, people)
+    person_mapper = mapper(Employee, employees)
     mapper(Engineer, engineers, inherits=person_mapper)
     mapper(Manager, managers, inherits=person_mapper)
 
     {python title="Multiple Table Inheritance, Polymorphic"}
     person_join = polymorphic_union(
         {
-            'engineer':people.join(engineers),
-            'manager':people.join(managers),
-            'person':people.select(people.c.type=='person'),
+            'engineer':employees.join(engineers),
+            'manager':employees.join(managers),
+            'person':employees.select(employees.c.type=='person'),
         }, None, 'pjoin')
 
-    person_mapper = mapper(Person, people, select_table=person_join, polymorphic_on=person_join.c.type, polymorphic_identity='person')
+    person_mapper = mapper(Employee, employees, select_table=person_join, polymorphic_on=person_join.c.type, polymorphic_identity='person')
     mapper(Engineer, engineers, inherits=person_mapper, polymorphic_identity='engineer')
     mapper(Manager, managers, inherits=person_mapper, polymorphic_identity='manager')
 
+
 The join condition in a multiple table inheritance relationship can be specified explicitly, using `inherit_condition`:
 
     {python}