Hi, all.
I'm trying to get a many-to-many relationship, where each side of that
relationship is the same table, and where there's an association
object between them to hold data about the particular relationship.
I'm using SQLAlchemy 0.5rc4.
>From the examples on the documentation, and some Googling, I have a
basic idea of how to a) do a many-to-many relationship on the same
table, and b) use an association object, but when it comes to
combining the two I'm a bit lost.
For example, I have:
dbThing = sql.Table('Thing', DatabaseMetadata,
sql.Column('thing_id', sql.Integer, key='id', primary_key=True,
autoincrement=True),
sql.Column('thing_type', sql.String(20), key='type',
nullable=False, index=True),
)
A 'thing' is actually an abstract sort of item, which other tables
"inherit" from to become more specific kinds of 'things'. I'm wanting
to be able to have arbitrary relationships between things with the
relationships themselves having an arbitrary type.
So one thing might have a "dependent" relationship on another thing.
To deal with the many-to-many relationship, I have:
dbThingLink = sql.Table('ThingLink', DatabaseMetadata,
sql.Column("thing_source", sql.Integer,
sql.ForeignKey(dbThing.c.id, ondelete="CASCADE"), key='source'),
sql.Column("thing_destination", sql.Integer,
sql.ForeignKey(dbAsset.c.id, ondelete="NO ACTION"),
key='destination'),
sql.Column("link_type", sql.String(100), key='type',
nullable=False, default=''),
)
Just how to configure the mappers has be sa bit lost at this point.
Any pointers?
Thanks for any help.
--Stephen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---