On Sep 18, 2009, at 7:44 PM, joeformd wrote:

>
> Is there a simple way in SQLA to check if a relationship exists
> between two rows in a many-to-many situation, where the relationship
> is defined using another table?
>
> eg. the join table might look like this:
>
> user_towns = Table('user_towns', Base.metadata,
>    Column('user_id', Integer, ForeignKey('users.id')),
>    Column('town_id', Integer, ForeignKey('towns.id'))
> )
>
> to check if a relationship exists, the SQL would be fairly simple,
> with no joins required (is there a row in this table where user.id =
> user_id and town.id = town_id)
>
> Is there a simple way of asking this using SQLA, with the query
> syntax?

the simplest would be query(User.id).join(User.towns).filter 
(User.id==uid).filter(Town.id==tid). 
  

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to