this assumes each House will point to a unique Roof object (i.e., its a one-to-one relationship to a Roof). also if you use the latest trunk (or 2.3 when i release it this weekend) you can declare the mappers in any order. houses ---------- house_id integer pk name varchar roofs ------- roof_id integer pk house_id integer references houses(house_id) -- or put roof_id on the houses table, same diff name varchar type varchar concrete_roofs -------------------- roof_id integer pk references roofs(roof_id) hardness varchar wood_roofs ---------------- roof_id integer pk references roofs(roof_id) treename varchar metadata = BoundMetaData('some://db') (houses, roofs, concete_roofs, wood_roofs) = [Table(name, metadata, autoload=True) for name in ['houses', 'roofs', 'concrete_roofs', 'wood_roofs']] class House(object):pass class Roof(object):pass class ConcreteRoof(Roof):pass class WoodRoof(Roof):pass mapper(House, houses, properties={ 'roof':relation(Roof, uselist=False, cascade="all, delete-orphan", backref=backref("house")) }) roof_union = polymorphic_union( { 'concrete':concrete_roofs.join(roofs), 'wood':wood_roofs.join(roofs), }, None, 'roof_union' ) mapper(Roof, roofs, select_table=roof_union, polymorphic_on=roofs.c.type) mapper(ConcreteRoof, concrete_roofs, inherits=Roof, polymorphic_identity='concrete') mapper(WoodRoof, wood_roofs, inherits=Roof, polymorphic_identity='wood') On Jun 16, 2006, at 7:43 AM, Koen Bok wrote: Maybe a little metaphor to make it more simple. |
_______________________________________________ Sqlalchemy-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

