Thanks for the quick answers. But I'm left with some side-effect I'm a
little bit struggling with: in order for this to work myObject and
myOtherObject need to inherit some base class let's say 'entity'. Now
the ones who created the database clearly didn't had much experience
with databases (damn MS Access for making databases that accessible!)
because they simply put several unrelated objects into one table. The
objects share some properties, for example 'name', but they also have
other properties specific for the object (so column 'x' only has
relevance for type 1 and column 'y' only for type 2 and so on). Don't
tell me this is wrong, I know and I want to correct this, but I simply
can't at this stage since to many apps out there depend on this
structure. So actually I want myObject and myOtherObject to inherit
only from 'object'. Can this be done?

On Thu, Sep 4, 2008 at 9:01 AM,  <[EMAIL PROTECTED]> wrote:
>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to