On Sep 22, 2009, at 3:42 AM, Iwan wrote:

>
> Hi there,
>
> this is perhaps a stupid question, but we can't get it figured out
> from the docs on inheritance...
>
> Is it possible in sqlalchemy to have a hierarchy of classes of which
> only the root class in the hierarchy is mapped to the database at
> all.  (So the subclasses do not have any persisted attributes of their
> own, and are all in essence mapped to the same table.)
>
> I suppose single inheritance would work here, but I'd like to keep
> open the option of one day adding one special subclass which DOES in
> fact want to persist extra attributes - this time using joined table
> inheritance.
>
> Is something (or a mix) like this possible?

it is absolutely possible.   Any subclass mapper that does not have a  
"table" attribute will map as single table inheritance to the  
superclass.  Any mapper in the inheritance hierarchy that does declare  
"table" will be mapped to a join of that table against the parent's  
mapped table (or join).   so single/joined can be mixed in any  
combination.

It is possible that there would be some query idiosyncrasies when  
switching a class from single to joined or vice versa - such as if you  
filter on a subclass attribute, joined table  inheritance would  
require such features as "with_polymorphic" or "of_type" (or querying  
among the underlying tables directly, something I do often), whereas  
single table inheritance would be more straightforward.  So while  
switching is not that hard, its also not 100% transparent either.

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