there's no "registry" of tables to mappers.   You'd need to track that 
yourself, or otherwise scan through all mappers (non-public attribute 
sqlalchemy.orm._mapper_registry)  looking for tables (each mapper has a 
.local_table attribute).   Note that many mappers can be created against a 
single table.

To track yourself:

from sqlalchemy.orm import mapper as _mapper
import collections

my_registry_of_tables = collections.defaultdict(set)
def mapper(cls, table=None, *arg, **kw):
    my_registry_of_tables[table].add(cls)
    return _mapper(cls, table, *arg, **kw)

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base(mapper=mapper)



On Mar 7, 2011, at 11:51 PM, James Mills wrote:

> Hello,
> 
> Given a scenario where you're using declarative_base(...) and defining classes
> 
> Is there a way to ask SA what the mapper class (declarative) is for a given 
> table
> by inspecting something in metadata["table_name"] ?
> 
> cheers
> James
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to