joining to a subquery is better accomplished outside of relation()
using query, such as query(USZipCode).join((subquery,
subquery.c.col==USZipCode.somecol)).
Now you want it as an attribute on your class. Do it like this:
class USCity(object):
...
@property
def zipcode_meta(self):
return object_session(self).query(USZipCode).join(...join
criterion...).params(..whatever...)
The advantage to this is that you can formulate the query and its
relation to the parent in exactly the way you need.
On Nov 18, 2008, at 9:34 PM, indigophone wrote:
>
> zipcode_meta_join_subquery = session.query(us_zipcode_table.c.city_id,
> us_zipcode_table.c.zipcode_population,
> us_zipcode_table.c.average_house_value).group_by(us_zipc
> ode_table.c.city_id).subquery()
>
> mapper(USCity, us_city_table, properties={
> 'state':relation(USState, backref=backref('cities')),
> 'zipcode_meta':relation(USZipCode, primaryjoin=
> (zipcode_meta_join_subquery,
> zipcode_meta_join_subquery.c.city_id==us_city_table.c.city_id))
> })
>
> The above code obviously doesn't work. How do I add a join to the
> above subquery in my mapper?
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---