[This message has also been posted.]
Hi Eric,

Thanks very much for the improvement.

On Tue, 2 Dec 2008 15:04:34 -0800 (PST), Eric Ongerth
<[EMAIL PROTECTED]> 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()

Yes, I was looking for this, and printed out obj.__dict__ but didn't
see it there. A dictionary of attributes is very useful in theory, but
doesn't always seem to have all attributes. Is this documented
anywhere?

> Not too difficult.  You can also use type(obj) instead of
> obj.__class__.

I thought of trying this, but didn't. It didn't seem likely to work,
anyway. Is either of these preferred over the other in terms of API
stability, and if so, why?

> Furthermore, if you really need to determine the object's class's
> mapped table,
> obj_table = obj.__class__._sa_class_manager.mapper.mapped_table
>
> Of course, being an underscored thing, _sa_class_manager is not
> something you should count on from version to version of sqlalchemy,
> so keep that in consideration and don't use it anywhere you don't plan
> to maintain.

Not sure what the object class's mapped table is, but will look it up.

                                                      Regards, Faheem.

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