> -----Original Message----- > From: sqlalchemy@googlegroups.com > [mailto:sqlalch...@googlegroups.com] On Behalf Of darkblueB > Sent: 19 August 2009 02:58 > To: sqlalchemy > Subject: [sqlalchemy] Re: new questions >
> Hi Simon > > thanks for the reply.. Your second part is straightforward.. > The first one, not so much.. > > I have gone back to a simple > meta.bind = //my engine here > meta.reflect() > > I can see meta.tables, and meta.tables_sorted() > but how do I know what mapped objects exist? > > (there should be about 12 tables, with a few one to many and one many > to many defined) > I feel like time is passing by, I would like to use ORM but this is > new to me > thanks much > -Brian > Ah - I see what you mean now. meta.reflect() will only create Table objects (part of the SQL expression language layer). It doesn't automatically create mapped classes for you. If you want to use the declarative system, you would need to create at least a basic class for each of your reflected tables. For example (untested): import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base meta = sa.Metadata(bind='sqlite:///your.db') meta.reflect() Base = declarative_base(metadata=meta) class SomeObject(Base): __table__ = meta.tables['some_table'] class SomeOtherObject(Base): __table__ = meta.tables['some_other_table'] I suppose you could automate this by iterating over meta.tables and creating the classes in a loop. You would end up with something similar to SqlSoup (http://www.sqlalchemy.org/trac/wiki/SqlSoup). I suppose it should be possible to automatically create ORM-level relations by inspecting your foreign keys as well if you really wanted. Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---