Re: [sqlalchemy] Re: properties of query results if names overlap?

2016-03-09 Thread Mike Bayer
the name overlap situation is much improved in 1.1 to where it almost 
doesn't matter anymore:


http://docs.sqlalchemy.org/en/latest/changelog/migration_11.html#positional-matching-is-trusted-over-name-based-matching-for-core-orm-sql-constructs



On 03/09/2016 05:40 PM, Alex Hall wrote:

I think I answered my own question: the result variable gets
properties named for the column names, as usual, but those properties
are each under their respective table names. Those table names come
from the actual table name (I'm using auto-map) or, presumably, the
__tablename__ variable for declarative bases. That is:

for result in results:
  print result.items.itm_id
  print result.assignments.itm_id

At least, this is working for now. Please let me know if I'm missing a
piece or need to know more before some future bit of code turns out to
hide a gotcha I don't yet know about. Thanks.

On 3/9/16, Alex Hall  wrote:

Hi all,
Just a quick question: what does SA do if names overlap? For example,
in assignmentTable, there's a column called itm_id. In
attachmentTable, there's also a column called itm_id, and there's one
in itemTable as well. If I combine these in a kind of join, as in:

results = session.query(assignmentTable, attachmentTable)\
  .filter(assignmentTable.itm_id == attachmentTable.itm_id)\
  .all()

for result in results:
  print result.itm_id

What will that print? I love SA's named properties for query results,
and would much rather use them than indexes if possible. Is this just
not allowed for name overlaps, or does SA do some trick with the table
names to allow it? Thanks!





--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Re: properties of query results if names overlap?

2016-03-09 Thread Alex Hall
I think I answered my own question: the result variable gets
properties named for the column names, as usual, but those properties
are each under their respective table names. Those table names come
from the actual table name (I'm using auto-map) or, presumably, the
__tablename__ variable for declarative bases. That is:

for result in results:
 print result.items.itm_id
 print result.assignments.itm_id

At least, this is working for now. Please let me know if I'm missing a
piece or need to know more before some future bit of code turns out to
hide a gotcha I don't yet know about. Thanks.

On 3/9/16, Alex Hall  wrote:
> Hi all,
> Just a quick question: what does SA do if names overlap? For example,
> in assignmentTable, there's a column called itm_id. In
> attachmentTable, there's also a column called itm_id, and there's one
> in itemTable as well. If I combine these in a kind of join, as in:
>
> results = session.query(assignmentTable, attachmentTable)\
>  .filter(assignmentTable.itm_id == attachmentTable.itm_id)\
>  .all()
>
> for result in results:
>  print result.itm_id
>
> What will that print? I love SA's named properties for query results,
> and would much rather use them than indexes if possible. Is this just
> not allowed for name overlaps, or does SA do some trick with the table
> names to allow it? Thanks!
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.