move ddlevents dispatch to SchemaItem; "before_parent_attach", "after_parent_attach" to all SchemaItem classes; replace column._on_table_attach with event

Issue #2037 resolved
Mike Bayer repo owner created an issue

No description provided.

Comments (6)

  1. Mike Bayer reporter

    then update the recipe at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/NamingConventions to use the events. Remove the usage of Column subclasses:

    def pk_col(**kw):
        kw['primary_key']('primary_key') = True
        col = Column(Integer, **kw)
    
        def parent_attach(schema_item, parent):
            schema_item.name = '%s_id' % parent.name
            schema_item.doc = "Primary key column for %r" % parent.name
    
        event.listen(col, 'before_parent_attach', parent_attach)
        return col
    
  2. Mike Bayer reporter
    --- a/lib/sqlalchemy/schema.py  Sun Jan 30 15:08:41 2011 -0500
    +++ b/lib/sqlalchemy/schema.py  Sun Jan 30 18:24:35 2011 -0500
    @@ -66,6 +66,11 @@
    
             raise NotImplementedError()
    
    +    def _set_parent_with_dispatch(self, parent):
    +        self.dispatch.before_parent_attach(self.parent)
    +        self._set_parent(parent)
    +        self.dispatch.after_parent_attach(self.parent)
    +
         def get_children(self, **kwargs):
             """used to allow SchemaVisitor access"""
             return []
    
  3. Log in to comment