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 ID of one of Addresses of a given User?

I could do that just iterating over the addresses:

for address in user.addresses:
     if address.id == ID:
        print "TADA!"

... but this doesn't seem like a good solution. There must be a way to
make SQLAlchemy to return the value.

(to make it a bit more interesting - the code needs to be generic,
i.e. the function just gets some SA-mapped object and property name,
so I can't just build a query manually like this -

addr = session.query(Address).filter(id=address_id).filter(user_id =
user.id).one()

- because I don't know what the join fields are (and if possible I'd
like this to work with many-to-many relations too)
)

Thanks!

--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to