that specified an existing table using __table__.
mapping than you'd normally get with explicit `mapper()`
calls unless you set up the `exclude_properties` arguments
explicitly.
+
+ - It's an error to add new Column objects to a declarative class
+ that specified an existing table using __table__.
- mysql
- Added the missing keywords from MySQL 4.1 so they get escaped
*(tuple(cols) + tuple(args)), **table_kw)
else:
table = cls.__table__
-
+ if cols:
+ raise exceptions.ArgumentError("Can't add additional columns when specifying __table__")
+
mapper_args = getattr(cls, '__mapper_args__', {})
if 'inherits' not in mapper_args:
inherits = cls.__mro__[1]
mapper_args['exclude_properties'] = exclude_properties = \
set([c.key for c in inherited_table.c if c not in inherited_mapper._columntoproperty])
exclude_properties.difference_update([c.key for c in cols])
-
+
cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff, **mapper_args)
class DeclarativeMeta(type):
class User(Base):
id = Column('id', Integer, primary_key=True)
self.assertRaisesMessage(sa.exc.InvalidRequestError, "does not have a __table__", go)
+
+ def test_cant_add_columns(self):
+ t = Table('t', Base.metadata, Column('id', Integer, primary_key=True))
+ def go():
+ class User(Base):
+ __table__ = t
+ foo = Column(Integer, primary_key=True)
+ self.assertRaisesMessage(sa.exc.ArgumentError, "add additional columns", go)
def test_undefer_column_name(self):
# TODO: not sure if there was an explicit