Michael Bayer wrote:
are you wondering....*why* this happens ? its because your mixin is
giving all classes a __tablename__.
Well, that's only a symptom of the problem, here's another example:
def test_mapper_args_single_table(self):
class CommonColumns:
id = Column(Integer, primary_key=True)
class BaseType(Base, CommonColumns):
__tablename__ = 'base'
discriminator = Column('python_type', String(50))
__mapper_args__= dict(polymorphic_on=discriminator)
value = Column(Integer())
class SpecificType1(BaseType):
__mapper_args__ = dict(polymorphic_identity='type1')
class SpecificType2(BaseType):
__mapper_args__ = dict(polymorphic_identity='type2')
======================================================================
ERROR:
test.ext.test_declarative.DeclarativeMixinTest.test_mapper_args_single_table
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/mnt/Users/chris.withers/sqlalchemy_env/lib/python2.6/site-packages/nose-0.11.3-py2.6.egg/nose/case.py",
line 186, in runTest
self.test(*self.arg)
File
"/mnt/Users/chris.withers/sqlalchemy/test/ext/test_declarative.py", line
2224, in test_mapper_args_single_table
class SpecificType1(BaseType):
File
"/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/ext/declarative.py",
line 725, in __init__
_as_declarative(cls, classname, cls.__dict__)
File
"/mnt/Users/chris.withers/sqlalchemy/lib/sqlalchemy/ext/declarative.py",
line 696, in _as_declarative
"Can't place primary key columns on an inherited class with no table."
ArgumentError: Can't place primary key columns on an inherited class
with no table.
I'm thinking that declarative should ignore columns, __table_args__ and
__tablename__ from mixins where a base of the class being dealt with is
already mapped (implying some kind of table inheritence, right?).
I can see situations where you'd want mixins to work as they currently
do (which causes the above test failure) with concrete and joined table
inheritence, but in that case, you can just use the mixin on both the
parent and the child classes, right?
cheers,
Chris
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.