On Dec 2, 2008, at 6:04 PM, Eric Ongerth wrote:

>
> def add_obj(session, obj):
>     """ Check if object primary key exists in db. If so,exit, else
>     add.
>     """
>     pid = obj.id
>    if session.query(obj.__class__).filter_by(id=pid).count():
>         print "Patient object with id %s is already in db."%pid
>         exit
>     else:
>         session.save(obj)
>         session.commit()
>
>
> Not too difficult.  You can also use type(obj) instead of
> obj.__class__.
>
> Furthermore, if you really need to determine the object's class's
> mapped table,
> obj_table = obj.__class__._sa_class_manager.mapper.mapped_table

here's the API way:

object_mapper(obj).mapped_table



--~--~---------~--~----~------------~-------~--~----~
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