This could perhaps be improved in the interface; "aliased()" applies to mapped classes and mappers. join() is a Selectable expression. To alias a selectable, use its alias() method to generate an alias object:
join(A, B).alias()
I'll think about having orm.aliased() detect a selectable and return selectable.alias() in 0.7.
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> Okay, so I implemented "join(A, B).alias()", but I can't seem to access the columns of the aliased table. Here is my code:
>
>
> session = sessionfactory()
>
> combined_1 = join(DiskFile, Header).alias()
> combined_2 = join(DiskFile, Header).alias()
>
> query = session.query(header).select_from(combined_1, combined_2).filter(DiskFile.canonical == True).filter(Header.datalab != 'none').filter(combined_1.datalab == combined_2.datalab)
>
>
> And I get:
> AttributeError: 'Alias' object has no attribute 'datalab'
>
>
When you work with join() and alias() objects, you start using the SQL expression language. The objects are known as "selectables" and their namespace of column attributes is available via the .c. attribute.
It's advisable to get a feel for SQL expression constructs via the tutorial: http://www.sqlalchemy.org/docs/core/tutorial.html . You can probably skim the first half of it then start looking at the sections on "Aliases" and "Joins" more closely.