On Sep 20, 2013, at 12:33 AM, Nathan Mailg <nathanma...@gmail.com> wrote:
> On Sep 19, 2013, at 3:07 PM, Michael Bayer <mike...@zzzcomputing.com> wrote: >> >> On Sep 19, 2013, at 2:46 PM, Nathan Mailg <nathanma...@gmail.com> wrote: >> >>> c = aliased(City) >>> q2 = s.query(q1).\ >>> join(Appl.city).\ >>> join(c, Appl.city).\ >>> order_by(q1.c.lastname, q1.c.firstname) >> >> why don't you join on the Column objects present rather than relying on the >> relationship? > > Sorry, I don't know. I'm sure I'm missing something basic that's obvious to > you. :) > > Do you mean something like this? > > q2 = s.query(q1).\ > join(City, City.id==q1.c.cityid).\ > order_by(q1.c.lastname, q1.c.firstname) > > That's all I've been able to get to work. I think I've been spoiled by > relationship() using declarative. :) that's what I meant, yup. So you *can* do the query, you're just missing a particular convenience feature in this case. > What I'm trying to get at are the attrs on City, like: > > # row is KeyedTuple instance > for row in q2.all(): > # this works > print row.lastname > # below does not work, > # stuck here trying to get at joined City attrs, e.g. City has a "name" > attr > print row.city.name > Ok now I'm still not following - in this case, "row" is a NamedTuple, or a mapped instance? if its a NamedTuple then you don't have the service of traversing along object relationships available since the NamedTuple isn't a mapped object. You'd need to query for a full object with an identity ( query(MyClass) as opposed to query(MyClass.col1, MyClass.col2, ...) if you provide me with *very minimal, but working* mappings and the query we're working on, I can show you how to make it load entities rather than rows.
signature.asc
Description: Message signed with OpenPGP using GPGMail