meaning, you can make mappers like this:
page_join = page_table.outerjoin(magazine_page_table).outerjoin
(classified_page_table)
magazine_join = page_table.join(magazine_page_table).outerjoin
(classified_page_table)
page_mapper = mapper(Page, page_table, select_table=page_join,
polymorphic_on=page_table.c.type, polymorphic_identity='p')
magazine_page_mapper = mapper(MagazinePage, magazine_page_table,
select_table=magazine_join, inherits=page_mapper,
polymorphic_identity='m')
classified_page_mapper = mapper(ClassifiedPage,
classified_page_table, inherits=magazine_page_mapper,
polymorphic_identity='c')
full example attached.
conclusions we can draw from this ? I am really, really dumb for not
seeing this for like, the past year. the queries are a lot easier to
create and read, plus we avoid all the other issues UNIONS bring
forth (like same column name but different types colliding, etc).
> conclusions we can draw from this ? I am really, really dumb for
> not seeing this for like, the past year. the queries are a lot
> easier to create and read, plus we avoid all the other issues
> UNIONS bring forth (like same column name but different types
> colliding, etc).
well, u have paid the bill - all those corresponding_column,
column_equivalents etc complications (and i run into those yesterday
again, trying to automate expression-generation over a polymorphic
base...)
==============
some questions arise around the example, trying to generalise it for
any levels:
- page_join and magazine_page_join are _same_; classifed has just its
table as localtable. Should this mean, that genericaly, leafs need
just their table, and all non-leafs need same outerjoins of the full
hierarchy (i.e. the root one)
- how u do a branch in the hierahcy? i.e. to have DocumentPage(page),
sibling to magazinePage?
cheers
svilen
Thanks for the insight. Wish I'd thought of it earlier too. Funny,
though; only three weeks after this came up, I'm replacing most of my
more complicated uses of polymorphism with more of a 'vertical tables'
approach. I'd likely be months behind where I am now if not for
sqlalchemy. Thanks for all the tools.
> polymorphic.py
> 1KDownload
>
>
can u explain a bit to one of the "polymorhists" :-)
i mean, i dont give a shit if its polymunion or else, i just want my
class tree to go into sql and then get it back sanely.
so far i see that if i have inheritance A-B-C-D, this approach works;
but if i have A-B-C and B-D, or A-B-C and A-D-E, i can't see how.
or i am not understanding something?
ta
svil