I am trying to create a function that finds the dependent tables used in a 
select-able statement. My plan is to use this function in conjunction with 
*t.add_is_dependent_on* inside a modified version of the recipe to create 
views. Hopefully, this allows *sorted_tables* to use these dependency 
relationships. The function definitely seems to work when the selectable 
only involves base tables, but breaks when a view uses another view. I 
think if I modify the function to recursively cycle through elements that 
are Selectables it should do the trick, but I was wondering if there is a 
public method like *_from_objects */ already a function to do something 
similar to this in the library?


def find_selectable_dependents(selectable):
   dependents = set()
    for part in selectable.froms:
        for obj in part._from_objects:
            if hasattr(obj, 'element'):
                table_ = obj.element
                dependents.add(table_)

    return list(dependents)

def view(name, metadata, selectable):
    t = table(name)

    for c in selectable.c:
        c._make_proxy(t)

    CreateView(name, selectable).execute_at('after-create', metadata)
    DropView(name).execute_at('before-drop', metadata)


    dependents = find_selectable_dependents(selectable)
    for dependent in dependents:
        t.add_is_dependent_on(dependent)

    return t


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to