Hello all,

I've been playing a bit with polymorphic concrete inheritance, and
noticed that when you have several levels of "polymorphic" loading (ie
my child class is also a parent class which I want to load
polymorphically), the query for the top-level class includes the child
polymorphic join while I don't see any reason to (its table is already
contained in the parent join). See attached example.

class A(object):
    ...

class B(A):
    pass

class C(B):
    pass

The query ends up something like:

SELECT [all_columns] FROM ([pjoin_abc]), ([pjoin_bc])

Am I using it wrong, or is this a bug?

-- 
Gaƫtan de Menten
http://openhex.org

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

from sqlalchemy import *
from sqlalchemy.orm import *

metadata = MetaData()
metadata.bind = 'sqlite:///'

a_table = Table('a', metadata,
    Column('id', Integer, primary_key=True),
    Column('data1', String(20))
)
b_table = Table('b', metadata,
    Column('id', Integer, primary_key=True),
    Column('data1', String(20)),
    Column('data2', String(20))
)
c_table = Table('c', metadata,
    Column('id', Integer, primary_key=True),
    Column('data1', String(20)),
    Column('data2', String(20)),
    Column('data3', String(20))
)

metadata.create_all()

class A(object):
    def __init__(self, **kwargs):
        for k, v in kwargs.iteritems():
            setattr(self, k, v)

class B(A):
    pass

class C(B):
    pass

pjoin_all = polymorphic_union({
    'a': a_table,
    'b': b_table,
    'c': c_table
}, 'type', 'pjoin')

pjoin_bc = polymorphic_union({
    'b': b_table,
    'c': c_table
}, 'type', 'pjoin_bc')


a_m = mapper(A, a_table,
             with_polymorphic=('*', pjoin_all),
             polymorphic_on=pjoin_all.c.type,
             polymorphic_identity='a')
b_m = mapper(B, b_table,
             inherits=a_m, concrete=True,
             with_polymorphic=('*', pjoin_bc),
             polymorphic_on=pjoin_bc.c.type,
             polymorphic_identity='b')
c_m = mapper(C, c_table,
             inherits=b_m, concrete=True,
             polymorphic_identity='c')

Session = sessionmaker()
session = Session()

a1 = A(data1='a1')
b1 = B(data1='b1', data2='b1')
c1 = C(data1='c1', data2='c1', data3='c1')

session.add(a1)
session.add(b1)
session.add(c1)
session.commit()

metadata.bind.echo = True

session.query(A).all()
print "*" * 20, "B", "*" * 20
session.query(B).all()

Reply via email to