[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Conor
Sergey V. wrote: Hi all, I must be missing something obvious here... Let's suppose I have the following class: class User(Base): # addresses = relation(Address, backref=user) and I have a number which may be an ID of an Address object. How do I check if the number is an

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Sergey V.
Some assumptions: 1. SA-mapped object means the user object in the example 2. property name means addresses in the example 3. The function shouldn't assume that you want an Address object 4. The ID attribute is known ahead of time (e.g. its always id). If not, your function will need

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Sergey V.
Ahh... I missed the relation.any() part of your example - with it the code should behave exactly as I need. I think. I need to give it a try. Thanks! On Oct 30, 9:53 am, Sergey V. sergey.volob...@gmail.com wrote: Some assumptions: 1. SA-mapped object means the user object in the example

[sqlalchemy] Re: Check if an item exists in a relation

2009-10-29 Thread Conor
Sergey V. wrote: Some assumptions: 1. SA-mapped object means the user object in the example 2. property name means addresses in the example 3. The function shouldn't assume that you want an Address object 4. The ID attribute is known ahead of time (e.g. its always id). If not, your function