We generally try to encourage users to create a new class, then map that, 
rather than removing mappings from an existing class.    If all references to a 
mapped class, including the mapper itself, are lost, the mapping is essentially 
"cleared".   

Removing the mapping from an individual class, while there is some API to do 
that, does not account for other mappers which may be referencing the target 
mapper, typically via relationship().   It also would cause any objects still 
lying around from that mapping to break if they were used again.   This is why 
making a new class is cleaner.    

There's a recipe creating new classes to map to new tables at:

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/EntityName

You'd also want to remove no-longer-used Table objects from the owning MetaData 
collection via metadata.remove(table).  Again, other tables which refer to this 
one via ForeignKey will retain strong references to the target, preventing it 
from being garbage collected.


On Aug 30, 2011, at 9:03 AM, Amit Sethi wrote:

> Hi all , I am a sqlalchemy noom , I am using sqlalchemy on top of a
> php app(mysql) that actually decides to create a new table in certain
> situations . So in one of the queries I have to create and load a
> table dynamically. I am doing this in this fashion.
> 
> class Z_Current(object):
>   pass
> 
> 
> z_current = Table('z_%s' %result_id , metadata, autoload=True)
> 
> try:
>    class_mapper(Z_Current)
> except UnmappedClassError:
>    mapper(Z_Current,z_current,primary_key = [z_current.c.id])
> 
> But I need to clear a mapper to load another table . Is it possible
> for me to clear one mapper.
> 
> -- 
> A-M-I-T S|S
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to