- Declarative will properly interpret the "foreign_keys" argument
on a backref() if it's a string.
+ - Declarative will accept a table-bound column as a property
+ when used in conjunction with __table__, if the column is already
+ present in __table__. The column will be remapped to the given
+ key the same way as when added to the mapper() properties dict.
+
0.5.2
======
else:
table = cls.__table__
if cols:
- raise exceptions.ArgumentError("Can't add additional columns when specifying __table__")
+ for c in cols:
+ if not table.c.contains_column(c):
+ raise exceptions.ArgumentError("Can't add additional column %r when specifying __table__" % key)
mapper_args = getattr(cls, '__mapper_args__', {})
if 'inherits' not in mapper_args:
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))
+ t = Table('t', Base.metadata, Column('id', Integer, primary_key=True), Column('data', String))
def go():
class User(Base):
__table__ = t
foo = Column(Integer, primary_key=True)
- self.assertRaisesMessage(sa.exc.ArgumentError, "add additional columns", go)
+ # can't specify new columns not already in the table
+ self.assertRaisesMessage(sa.exc.ArgumentError, "Can't add additional column 'foo' when specifying __table__", go)
+
+ # regular re-mapping works tho
+ class Bar(Base):
+ __table__ = t
+ some_data = t.c.data
+
+ assert class_mapper(Bar).get_property('some_data').columns[0] is t.c.data
def test_undefer_column_name(self):
# TODO: not sure if there was an explicit