test coverage for attachment events - constraints + recipe on the wiki for naming scheme
Issue #2105
resolved
diff -r de529fb81cc80cd49666a80ef60de6015ff81c1c lib/sqlalchemy/schema.py
--- a/lib/sqlalchemy/schema.py Wed Mar 23 17:38:54 2011 -0400
+++ b/lib/sqlalchemy/schema.py Thu Mar 24 20:44:31 2011 -0400
@@ -239,7 +239,7 @@
self.indexes = set()
self.constraints = set()
self._columns = expression.ColumnCollection()
- self._set_primary_key(PrimaryKeyConstraint())
+ PrimaryKeyConstraint()._set_parent_with_dispatch(self)
self.foreign_keys = set()
self._extra_dependencies = set()
self.kwargs = {}
#!python
def _pk_constraint_name(const, table):
const.name = "pk_%s" % (table.name, )
event.listen(PrimaryKeyConstraint, "after_parent_attach", _pk_constraint_name)
def _fk_constraint_name(const, table):
fk = list(const.elements)[0](0)
reftable, refcol = fk._colspec.split(".")
const.name = "fk_%s_%s_%s" % (
table.name,
fk.parent.name,
reftable
)
event.listen(ForeignKeyConstraint, "after_parent_attach", _fk_constraint_name)
def _unique_constraint_name(const, table):
const.name = "uq_%s_%s" % (
table.name,
list(const.columns)[0](0).name
)
event.listen(UniqueConstraint, "after_parent_attach", _unique_constraint_name)
Comments (3)
-
reporter -
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.7.0 (automated comment)
- Log in to comment
ae363b0663a8b67f39d2970a6fe0626c54c1478c