see (single) table inheritance and the rest, http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_inheritance
On Wednesday 03 September 2008 21:59:28 [EMAIL PROTECTED] wrote: > Hi all, > > I just started playing with SQLAlchemy today (after several years > of plain SQL experience) and I must say I'm impressed. I'm reading > my way through the docs now, but there is one thing I can't seem to > find. Let me briefly explain the situation. > > I was given the task of rewriting a database which is in use for > many years now. And since many applications depend on its current > structure I can only make small changes at the time. My plan is to > rewrite all the attached applications but this time abstracting the > app's logic from the data-structure itself. I think that SQLAlchemy > will allow me to achieve this task by building a library of POPO's > and some mappers to the data-structure. In that way I can rework > the database and only have to adapt the mappers to keep my app's > running. So I started that and immediately stumbled upon a 'common' > situation which I don't now how to solve in SQLA. So here goes: > > I have 1 table (mytable) which is structured somewhat like this: > id = int (primary key) > name = varchar() > type = int > > Now all rows with a type, say 1 'constitute' a MyObject. And rows > with type say 2 are MyOtherObject instances, and so on. So in my > applications I want to create a class like this: > > class MyObject(object): > def __init__(self, name): > self.name = name > > Then I need to map this to the database. So I write a mapper like > this: > myobject_table = select([mytable], mytable.c.type == > 1).alias('somealias') (not sure if this is entirely correct. I'm > writing this post at home and don't have access to my code at the > office. But this is not the point so...) > mapper(MyObject, myobject_table) > > So far all ok, but now when I insert new instances of type > MyObject, the type column is not filled with value 1. The instance > is inserted ok except for this 'hidden' column. I don't want to add > this column to my MyObject class since I foresee that the structure > of my DB will change and then there will be no more value for the > type column. The column 'type' belongs to the internals of my > data-structure and shouldn't be visible in my app's. In the new > structure there will be a table just for MyObject instances. > > Does any guru out there knows how to solve this rather 'common' > problem? > > Many thanks for reading this post! > > -- > Wim > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---