On Sep 26, 2008, at 9:23 AM, Doug Farrell wrote:

> I'm trying to represent a many-to-many relationship between the  
> press_table and the press_routing table using the linking table,  
> press_routing_press. I think I've got the table structure and  
> mapping set up, but now I need some help to build a query using  
> SqlAlchemy that does the same thing as this MySQL query:
>
> select p.id, p.code
> from press p
> inner join press_routing_press prp
> on p.id=prp.press_id
> inner join press_routing pr
> on pr.id=prp._press_routing_id
> where pr.code='A'
>
>

Hi Doug -

this kind of join is described at  
http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_joins 
  , the fourth example (albeit its for a one-to-many, the approach is  
the same with a "secondary" table).

The approach here is:

sess 
.query(Press).join(Press.routes).filter(PressRouting.code=='A').all()





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to