Single table inheritance

23 views
Skip to first unread message

Kent

unread,
Mar 21, 2012, 9:49:38 AM3/21/12
to sqlal...@googlegroups.com
Hoping for advice:  I'm using sqlalchemy against a legacy application's database design, most of which isn't in my control.  I have a situation where single table inheritance should work beautifully but there is one catch: of the 7 polymorphic sub classes, there is one which is allowed to change into another.  The rest are immutable.  As an example, suppose a Employee were allowed to be promoted to Manager. 

The docs state that the polymorphic_identity is a read only attribute and that "Behavior is undefined if directly modified." 

I could work around this by mapping 2 polymorphic_identities to one class, but as far a I can see, this can only be a single scalar value.  The docs say that polymorphic_on may also be of other types besides Column in a future SQLAlchemy release... I wonder if I can help sqla map either of 2 values to a class in this way?

Any advice?

Michael Bayer

unread,
Mar 21, 2012, 10:04:38 AM3/21/12
to sqlal...@googlegroups.com

did you try just saying employee.type = 'manager', flushing, then loading a new copy of it ?

also polymorphic_on can be any SQL expression in 0.7, like a CASE statement if you wanted.

Kent Bower

unread,
Mar 21, 2012, 10:29:07 AM3/21/12
to sqlal...@googlegroups.com
That will work for me, thanks!

P.S. make a note that the doc statement that it will be a future release
should be updated.

Michael Bayer

unread,
Mar 21, 2012, 10:46:43 AM3/21/12
to sqlal...@googlegroups.com

On Mar 21, 2012, at 10:29 AM, Kent Bower wrote:

> That will work for me, thanks!
>
> P.S. make a note that the doc statement that it will be a future release should be updated.

can you point me right to where it says that

>
> On 3/21/2012 10:04 AM, Michael Bayer wrote:
>> also polymorphic_on can be any SQL expression in 0.7, like a CASE statement if you wanted.
>

> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>

Kent Bower

unread,
Mar 21, 2012, 10:51:38 AM3/21/12
to sqlal...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages