<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">I'm building a search doo-dad and trying to describe criteria with chains of attributes, like might appear in a loading option: <code class="notranslate">Song.album, Album.artist, Artist.birth_year</code>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="* Some tables need to be joined to multiple times, so I have to alias every table involved to be safe.  If all I have is `attr = Song.album`, the best way I can find to create a corresponding alias is `getattr(aliased(attr.property.argument), attr.key)` -- which is ugly, not really documented, and doesn't work with association proxies and other special relationships that have no `key` attribute.

* After getting some result rows, I often want to retrieve the column data corresponding to some criteria; e.g. if the user searched for a range, it's helpful to show the actual values.  How do I get `some_song.album` given `Song.album`?  I've only come up with the `key` line above, or the slightly more &quot;correct&quot; `attr.__get__(type(some_song), some_song)`."><pre class="notranslate"><code class="notranslate">* Some tables need to be joined to multiple times, so I have to alias every table involved to be safe.  If all I have is `attr = Song.album`, the best way I can find to create a corresponding alias is `getattr(aliased(attr.property.argument), attr.key)` -- which is ugly, not really documented, and doesn't work with association proxies and other special relationships that have no `key` attribute.

* After getting some result rows, I often want to retrieve the column data corresponding to some criteria; e.g. if the user searched for a range, it's helpful to show the actual values.  How do I get `some_song.album` given `Song.album`?  I've only come up with the `key` line above, or the slightly more "correct" `attr.__get__(type(some_song), some_song)`.
</code></pre></div>
<p dir="auto">I could just use string names of properties, I suppose, but I like the compile-time checking I get by using the actual objects.</p>
<p dir="auto">A more general comment: some of the recipes and examples are absolutely fabulous, but I'd never have guessed that SQLAlchemy was even capable of such things, let alone figured out how to implement them.  More documentation on extending SQLAlchemy itself would be phenomenally helpful.  Note, for example, that the docs for <code class="notranslate">ConnectionEvents</code> don't describe the events' arguments.</p>
<p dir="auto"><strong>Is your feature request related to a problem? Please describe.</strong></p>
<p dir="auto">In the next major version of <a href="https://python-gino.org" rel="nofollow">GINO</a> which will be built on SQLAlchemy 1.4, <code class="notranslate">AsyncConnection</code> is subclassed to be lazy (and together with many other contextual features, to be compatible with the current GINO version). It would be neat to put the lazy-connection initialization code in the overridden <code class="notranslate">AsyncConnection._sync_connection()</code> method to avoid a lot of code duplicates.</p>
<p dir="auto"><strong>Describe the solution you'd like</strong></p>
<p dir="auto">As demonstrated in <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/fantix/sqlalchemy/commit/async-sync-connection/hovercard" href="https://github.com/fantix/sqlalchemy/commit/async-sync-connection">fantix@<tt>async-sync-connection</tt></a>, making the <code class="notranslate">_sync_connection()</code> method sync would allow subclasses to blend in async logic to get the actual connection.</p>
<p dir="auto"><strong>Describe alternatives you've considered</strong></p>
<p dir="auto">Otherwise, the subclasses would have to override and copy over all <code class="notranslate">AsyncConnection</code> methods to add async logic.</p>
<p dir="auto"><strong>Additional context</strong></p>
<p dir="auto"><a href="https://github.com/python-gino/gino/blob/501840be96a875490fda39f43ed5139fdee56d5d/src/gino/engine.py#L154-L166">https://github.com/python-gino/gino/blob/501840be96a875490fda39f43ed5139fdee56d5d/src/gino/engine.py#L154-L166</a></p>
<p dir="auto"><strong>Have a nice day!</strong></p>