-Base entity is Party, which has sub-types Person and Organization.
-Using joined table inheritance, with base table 'parties', and sub-
tables 'people' and 'organizations'
-Want to create association class to capture various types of
relationships between parties.  Let's say this association would be
called PartyRelationship, which would be many-to-many between parties
to parties.
-Using declarative style

class Party(Base):
    __tablename__ = 'parties'
    type = Column(Integer)
    __mapper_args__ = {'polymorphic_on': type}
    id = Column(Integer, primary_key=True)
    name = Column(String)
    email = Column(String)
    password = Column(String)
    ..
    ..

class Person(Party):
    __tablename__ = 'people'
    id = Column(Integer, ForeignKey('parties.id'), primary_key=True)
    __mapper_args__ = {'polymorphic_identity': PartyTypes.PERSON}
    date_of_birth = Column(String)
    ..
    ..

class Organization(Party):
    __tablename__ = 'organizations'
    id = Column(Integer, ForeignKey('parties.id'), primary_key=True)
    __mapper_args__ = {'polymorphic_identity':
PartyTypes.ORGANIZATION}
    purpose = Column(String)
    ..
    ..

class PartyRelationship(Base):
    __tablename__ = 'party_relationships'
    from = Column(Integer, ForeignKey('parties.id'), primary_key=True)
    to = Column(Integer, ForeignKey('parties.id'), primary_key=True)
    type = Column(Integer) # there are different types of
relationships

How would I go about defining a relation in this scenario, which,
instead of being many-to-many between two different tables/objects, is
many-to-many for parties?

Brad

P.S. Really liking sqlalchemy so far.  Saves time but doesn't take
away control.

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to