Maps to explicit joins are in any case going to integrate poorly with  
the joins created by SQLA's inheritance functionality.  But in this  
case, no imitation of SQLA's join is needed:

orm.mapper(Lab, inherits=Group,
    polymorphic_identity=u"group_lab",
)



On Sep 6, 2008, at 1:24 PM, Jason Yamada-Hanff wrote:

> mport sqlalchemy as sa
> from sqlalchemy import types as t
> from sqlalchemy import orm
>
> engine = sa.create_engine('sqlite:///:memory:', echo=True)
> metadata = sa.MetaData()
>
> agents = sa.Table('agents', metadata,
>    sa.Column('id', t.Integer,
>        sa.Sequence('agents_id_seq', optional=True),
> primary_key=True),
>    sa.Column('type', t.Unicode(50),
>        sa.CheckConstraint("type IN ('agent', 'person', 'group',
> 'group_org', \
>                'group_lab', 'group_contactlist')"), nullable=False),
>    sa.Column('notes', t.UnicodeText),
> )
>
> groups = sa.Table('groups', metadata,
>    sa.Column('id', t.Integer, unique=True),
>    sa.Column('short_name', t.Unicode(50)),
>    sa.Column('name', t.Unicode(255), nullable=False),
>    sa.Column('group_status', t.Unicode(50),
>        sa.CheckConstraint("group_status IN ('active', 'not active',
> 'closed')"),
>            default=u'active', nullable=False),
>    sa.Column('description', t.UnicodeText),
>    sa.PrimaryKeyConstraint('id'),
>    sa.ForeignKeyConstraint(['id'], ['agents.id'],
>        onupdate="CASCADE", ondelete="CASCADE")
> )
>
>
> class Agent(object):
>    pass
>
> class Group(Agent):
>    pass
>
> class Lab(Group):
>    pass
>
>
> def map_agent_classes():
>    orm.mapper(Agent, agents,
>        polymorphic_on=agents.c.type,
>        polymorphic_identity=u"agent",
>        )
>
>    orm.mapper(Group, groups,
>        inherits=Agent,
>        polymorphic_identity=u"group",
>        )
>
>    lab_select =
> agents.outerjoin(groups).select(agents.c.type==u'group_lab',\
>            use_labels=True).alias('labs')
>    orm.mapper(Lab, lab_select,
>        inherits=Group,
>        polymorphic_identity=u"group_lab",
>    )
>
> map_agent_classes()
>
> metadata.create_all(engine)
> Session = orm.sessionmaker(bind=engine)
>
> sess = Session()
>
> lab = Lab()
> lab.name = u"Lab Name"
> lab.short_name = u"lab"
>
> sess.add(lab)
> sess.flush()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to