Is it possible to manually set the type column of a base class when
using single table inheritance? The reason I want to do this is
because I am importing data from an external source which does not
differentiate between the subclass types.

For example:

a_table = Table('a', metadata,
          Column('id', Integer, primary_key=True),
          Column('type', String(20)),
          Column('name', String(20))
          )

class A(object): pass
class B(A): pass

a_mapper = mapper(A, a_table, polymorphic_on=a_table.c.type,
polymorphic_identity='a', with_polymorphic='*')
b_mapper = mapper(B, inherits=a_mapper, polymorphic_identity='b')

Here, A is the base class and B is the subclass. I want to be able to
do this:

a = A()
a.type = 'b'

session.add(a)
result = session.query(A).all()

I expect the result to contain an instance of B because I have
explicitly set the type to 'b'. But right now, it looks like because I
have instantiated an instance of A, the type is overwritten as 'a'. Is
there any nice way to do this?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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