After some testing, the example I gave did not work properly.  queries 
executed with con did not reflect changes made in a session transaction. 
  This does seem to work:

         sess = object_session(self)
         con = sess.connection(self.mapper)

Seems messy.  self.mapper only exists because I assigned it.  I think 
otherwise, a object_mapper(self) would be required.  This works, but I 
think there must be a better way.

Randall

Randall Smith wrote:
> I'm wondering what is the best way for a mapped object to acquire a 
> connection for a non-ORM style query while staying within the context 
> (reuse connection or transaction) of its own session.  For example, here 
> is a method of a mapped object.
> 
>      @property
>      def analysis_count(self):
>          """Return a count of related analysis records.
> 
>          """
>          sess = object_session(self)
>          con = session.connect()
>          result = select([func.count(sample_analysis.c.id)], 
> 
>                          sample_analysis.c.batch_id == self.id,
>                          bind=con).execute().scalar()
>          return result
> 
> Is this correct and is there a better way to accomplish this?  I'm 
> working with SA 0.3.10.
> 
> Randall
> 
> 
> > 
> 


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