__table_args__ is passed as a tuple with no dict argument.
Improved documentation. [ticket:1468]
+ - Table objects declared in the MetaData can now be used
+ in string expressions sent to primaryjoin/secondaryjoin/
+ secondary - the name is pulled from the MetaData of the
+ declarative base. [ticket:1527]
+
- A column can be added to a joined-table subclass after
the class has been constructed (i.e. via class-level
attribute assignment). The column is added to the underlying
import sqlalchemy
def access_cls(key):
- try:
+ if key in cls._decl_class_registry:
return _GetColumns(cls._decl_class_registry[key])
- except KeyError:
+ elif key in cls.metadata.tables:
+ return cls.metadata.tables[key]
+ else:
return sqlalchemy.__dict__[key]
d = util.PopulateDict(access_cls)
compile_mappers()
eq_(str(User.addresses.property.primaryjoin), str(Address.user.property.primaryjoin))
+ def test_string_dependency_resolution_tables(self):
+ class User(Base, ComparableEntity):
+ __tablename__ = 'users'
+ id = Column(Integer, primary_key=True)
+ name = Column(String(50))
+
+ props = relation("Prop",
+ secondary="user_to_prop",
+ primaryjoin="User.id==user_to_prop.c.user_id",
+ secondaryjoin="user_to_prop.c.prop_id==Prop.id",
+ backref="users")
+
+ class Prop(Base, ComparableEntity):
+ __tablename__ = 'props'
+ id = Column(Integer, primary_key=True)
+ name = Column(String(50))
+ user_to_prop = Table('user_to_prop', Base.metadata,
+ Column('user_id', Integer, ForeignKey('users.id')),
+ Column('prop_id', Integer, ForeignKey('props.id')),
+ )
+
+ compile_mappers()
+ assert class_mapper(User).get_property("props").secondary is user_to_prop
+
def test_uncompiled_attributes_in_relation(self):
class Address(Base, ComparableEntity):
__tablename__ = 'addresses'