I am having some trouble getting the polymorphic multi-table inheritance
working in a project. I broke it down into a simple test case:
########################################################################
from sqlalchemy.ext.sessioncontext import SessionContext
from sqlalchemy.ext.assignmapper import assign_mapper
from sqlalchemy import MetaData, Table, \
Column, Integer, \
Unicode, ForeignKey, \
create_engine, \
create_session, \
polymorphic_union,
String
cstr = 'sqlite:///:memory:'
engine = create_engine(cstr, strategy='threadlocal')
metadata = MetaData()
metadata.connect(engine)
context = SessionContext(create_session)
outputs_table = Table('outputs', metadata,
Column('outputidentifier', Integer, primary_key=True),
Column('name', Unicode(64)),
Column('description', Unicode(128)),
Column('outputtype', String(30))
)
forms_table = Table('forms', metadata,
Column('outputidentifier', Integer,
ForeignKey('outputs.outputidentifier'), primary_key=True),
Column('dcl', Unicode(64))
)
formsets_table = Table('formsets', metadata,
Column('outputidentifier', Integer,
ForeignKey('outputs.outputidentifier'), primary_key=True)
)
class Output(object):
outputtype = 'output'
class Form(Output):
outputtype = 'form'
class FormSet(Output):
outputtype = 'formset'
outputs_join = polymorphic_union(
{
'form' : outputs_table.join(forms_table),
'formset' : outputs_table.join(formsets_table),
'output' : outputs_table.select(
outputs_table.c.outputtype=='output'
)
},
None, 'ojoin'
)
outputs_mapper = assign_mapper(context, Output,
select_table=outputs_join,
polymorphic_on=outputs_join.c.outputtype,
polymorphic_identity='output')
assign_mapper(context, Form, forms_table,
inherits=outputs_mapper,
polymorphic_identity='form')
assign_mapper(context, FormSet, formsets_table,
inherits=outputs_mapper,
polymorphic_identity='formset')
if __name__ == '__main__':
metadata.create_all()
f1 = Form(name='Form One')
########################################################################
I get the following stack trace:
########################################################################
Traceback (most recent call last):
File "test.py", line 64, in ?
f1 = Form(name='Form One')
File "/SQA036/sqlalchemy/orm/mapper.py", line 646, in init
mapper = mapper.compile()
File "/SQA036/sqlalchemy/orm/mapper.py", line 321, in compile
self._compile_all()
File "/SQA036/sqlalchemy/orm/mapper.py", line 336, in _compile_all
mapper._do_compile()
File "/SQA036/sqlalchemy/orm/mapper.py", line 362, in _do_compile
self._compile_inheritance()
File "/SQA036/sqlalchemy/orm/mapper.py", line 405, in
_compile_inheritance
self.inherits = self.inherits._do_compile()
File "/SQA036/sqlalchemy/orm/mapper.py", line 362, in _do_compile
self._compile_inheritance()
File "/SQA036/sqlalchemy/orm/mapper.py", line 450, in
_compile_inheritance
raise exceptions.ArgumentError("Mapper '%s' does not have a
mapped_table specified. (Are you using the return value of
table.create()? It no longer has a return value.)" % str(self))
sqlalchemy.exceptions.ArgumentError: Mapper 'Mapper|Output|None' does
not have a mapped_table specified. (Are you using the return value of
table.create()? It no longer has a return value.)
########################################################################
Any ideas what is going on?
--
Jonathan LaCour
http://cleverdevil.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---