test coverage for attachment events - constraints + recipe on the wiki for naming scheme

Issue #2105 resolved
Mike Bayer repo owner created an issue
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)

  1. Log in to comment