On Oct 21, 2013, at 5:20 PM, lars van gemerden <[email protected]> wrote:
> Hello,
>
> Say that i have a table with reports with a column 'title' and a one to many
> relationship 'chapters' to chapters also with a column 'title', if i join
> these tables in a query, like:
>
> q =
> self.session.query(Report).join(Report.chapters).add_columns(Report.title,
> Chapter.title, Chapter.text)
> for p in q.all():
> print p.title
>
> print p.title prints the title of the chapter.
>
> Is there a way to let the query.all() return NamedTuples with
> qualified/disambiguated names (either 'title' and 'chapters.title' or
> 'Report.title' and 'Chapter.title' or perhaps with underscores), because now
> i see no way to distinguish the columns (apart maybe from the order).
>
> p.keys() returns 'title' twice.
use labels:
add_columns(Report.title.label("report_title"),
Chapter.title.label("chapter_title"))
>
> Cheers, Lars
>
> PS: i am using sqla 0.7.5
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
signature.asc
Description: Message signed with OpenPGP using GPGMail
