Thanks! That's indeed the stuff I was looking for!

On Wed, Sep 3, 2008 at 9:23 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
> On Sep 3, 2008, at 2:59 PM, [EMAIL PROTECTED] wrote:
>
>>
>> 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)
>
> it is quite common and the pattern you describe is "single table
> inheritance".   You can map straight to the table and the "type"
> column will be taken care of for you.   You can configure subtypes
> corresponding to each value for "type" and Query for just that
> subclass (or for all classes).
>
> http://www.sqlalchemy.org/docs/05/mappers.html#advdatamapping_mapper_inheritance_single
>
> the feature is available in 0.4 and 0.5 but has some improvements to
> its behavior in the 0.5 series.
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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