On Fri Jan 18 15:40:25 2013, Simon King wrote:
On 18 Jan 2013, at 12:15, Kenny <bill...@mpimp-golm.mpg.de> wrote:

Hey all,

I'm quite new to SQLAlchemy and I've been struggling to get the following to 
work.

When one queries with specific entities, the resulting namedTuples might have 
overlapping keys.
e.g.

     sample = session.query(
             Sample.id,
             Experiment.id
         ).\
         join(Experiment).\
         filter(Experiment.active==1).\
         distinct().\
         first()
      print sample.id # will print experiment.id

So, how do access conflicting attributes?
I know I can use Sample.id.label('sample_id'), but I would prefer to have this 
in an automatic way. Much in the same way as the function with_labels() works 
on the query object, but then bubbling through to the actual result.
Any suggestions would be welcome!

wkr,
Kenny
ps: I am using SQLALchemy 0.7.3


I think you should be able to do this:

   print sample[Sample.id]
   print sample[Experiment.id]

Hope that helps,

Simon

Nope, that didn't do the trick. Anyone else have any suggestions?

Or is there any way to automatically add a label to all attributes in the same way as .label() does now?

wkr,
Kenny

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