On Aug 5, 2010, at 11:06 PM, anthony wrote: > Hi, > > First message here in the sqlalchemy mailing list. I was working with > a previous version of sqlalchemy (0.6beta1) and while updating > sqlalchemy, ran into a problem with polymorphic classes. Basically > we're using a single table inheritance scheme and we want the "value" > column to have different types. In the case of the example, the parent > is A, and I wanted child B and C to interpret the "value" column of > our table differently depending on the type. This worked in the > previous version of but no longer works :(. > > class A(Base): > id = Column(Integer) > type = Column(Integer) > __mapper_args__ = {'polymorphic_on': type} > > class B(A): > __mapper_args = {'polymorphic_identity': 1} > value = Column(Integer) > > class C(A): > __mapper_args = {'polymorphic_identity': 2} > value = Column(Boolean)
it works fine as expected with joined inheritance. With single table, it doesn't make any sense as "value" is a column on your table. Is the table column int or boolean ? I imagine you're hitting upon some sanity assertions that weren't in the beta version (always helpful if these details can be included...what style of inheritance, what does "no longer works :(" mean, etc.) If you want the subclasses to interpret the common "value" column, which here should probably be defined on A as the actual database column type, in different ways, use descriptors: class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) type = Column(Integer) _value = Column('value', String) __mapper_args__ = {'polymorphic_on': type} class B(A): __mapper_args = {'polymorphic_identity': 1} @property def value(self): return int(self._value) class C(A): __mapper_args = {'polymorphic_identity': 2} @property def value(self): return bool(self._value) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.