And btw, in case I didn't understand what you wanted and you really wanted to map one class to several tables, you'll find information about that there:
http://www.sqlalchemy.org/docs/adv_datamapping.html#advdatamapping_joins On 5/7/07, Gaetan de Menten <[EMAIL PROTECTED]> wrote: > On 5/7/07, Spider <[EMAIL PROTECTED]> wrote: > > > > I'm fairly new to this, and trying to understand the ORM relationship > > between a class and a table row. In most of the examples in the > > documentation, there is a one-to-one relationship; a class instance > > corresponds to a row of a table. > > > > In my application, my data falls into a 3-tier structure, represented > > by tables A, B and C. Each A has zero or more Bs, and each B and zero > > or more Cs. So, A->B is one-to-many, and B->C is one-to-many. > > > > >From an application perspective, the only type of entity is a "A", the > > only reason I have Bs and Cs is that SQL tables cannot have repeating > > columns (my previous database experience is with a non-SQL database > > that allows repeating data items!). I think of the Bs and Cs as just > > part of the particular A to which they belong. > > *If* I understood your point correctly (sorry if it's not the case), I > think you are looking for one-to-many relationships to the object > itself. This can very well be done. Just remember a one-to-many > relationship from A to B is expressed in your table as a foreignkey > from B to A ! > > http://www.sqlalchemy.org/docs/datamapping.html#datamapping_relations_onetomany > > > > > > Now, in Python I can represent all the data for a particular A (ie A+B > > +C) together in one item, say a nested dictionary. > > A nested dictionary will probably be quite hard to do with SQLAlchemy alone. > > > My question is, can the SQLAlchemy ORM do this for me - i.e. have a > > single class A which maps to my 3 tables A,B,C and "knows" how they > > are joined? If so, what should my class and table declarations look > > like (and for bounus points, can I specify the declaration using > > Elixir). > > In elixir, what you asked above (again assuming I understood what you > wanted) would translate to: > > class A(Entity): > has_field('name', String) # or whatever fields has the table > ... > belongs_to('parent', of_kind='A') > has_many('children', of_kind='A') > > -- > Gaëtan de Menten > http://openhex.org > -- Gaëtan de Menten http://openhex.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---