I recently shifted some of a database schema around, and thanks to `association_proxy`, I've almost-eliminated the need to adjust my code (thanks, Mike!).
I'm left with a situation on my caching layer that I can't seem to work out. I can't seem to to find out the following information (or other techniques that can help me figure out what I need) 1. what are the association_proxies on an object ? 2. have they been loaded ? the use-case is this: class Foo(base): id = Column(Integer, primary_key=True) bar = relationship( "Bar", primaryjoin="Foo.id==Bar.foo_id", uselist=False, ) bar_id = association_proxy("bar", "id") * I have a `Foo` instance, that may or may not have eagerloaded `Bar` into it. * I only want to access `bar_id` if `Bar` has been loaded. * I don't necessarily know that I have a `Foo` object or a `Bar`/`bar_id` relation, as I am accessing this in a generic caching routing. I can 'hint' this information into the object if needed. what I've tried/know: * sqlalchemy.orm.class_mapper(Foo).mapped_table.c does not have `bar_id` * sqlalchemy.orm.class_mapper(Foo).relationships does not have `bar_id`; but it does have `bar` * `fooInstance.__dict__` has a `bar` key when an eagerload happens But i can't find a way to look at `fooInstance` and infer what the association_proxies are. My initial thought is to declare this stuff explicitly, but if there is a way I could easily glean this information from the object, I think I may prefer to do that. does anyone have an idea? -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/322293a3-1605-45a9-abf8-c4ab29f3008f%40googlegroups.com.