<p dir="auto"><strong>Migrated issue, originally created by Andrey Popp (<a href="https://github.com/andreypopp">@andreypopp</a>)</strong></p>
<p dir="auto">Currently SQLAlchemy doesn't allow to map relationships which have primaryjoin condition like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="a.c.b_id + 2 == b.c.id"><pre class="notranslate"><code class="notranslate">a.c.b_id + 2 == b.c.id
</code></pre></div>
<p dir="auto">It just can't figure out the direction of relationships even if I supply a.c.b_id + 2 as foreign_keys element.</p>
<p dir="auto">dupe of</p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/2373/sqla_ticket_2373.2.py">sqla_ticket_2373.2.py</a> | <a href="../wiki/imported_issue_attachments/2373/sqla_ticket_2373.py">sqla_ticket_2373.py</a></p>
<p dir="auto"><strong>Migrated issue, originally created by Michael Bayer (<a href="https://github.com/zzzeek">@zzzeek</a>)</strong></p>
<p dir="auto">even though columns-as-keys is de-emphasized in the documentation for insert, it does work, except for multi-values:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sqlalchemy import *
from sqlalchemy.dialects import sqlite

t = table('t', column('a'), column('b'))

print t.insert().values([
    {&quot;a&quot;: 1, &quot;b&quot;: 2},
    {&quot;a&quot;: 2, &quot;b&quot;: 2},
    {&quot;a&quot;: 3, &quot;b&quot;: 2}
]).compile(dialect=sqlite.dialect())


print t.insert().values([
    {t.c.a: 1, t.c.b: 2},
    {t.c.a: 2, t.c.b: 2},
    {t.c.a: 3, t.c.b: 2},
]).compile(dialect=sqlite.dialect())"><pre class="notranslate"><code class="notranslate">from sqlalchemy import *
from sqlalchemy.dialects import sqlite

t = table('t', column('a'), column('b'))

print t.insert().values([
    {"a": 1, "b": 2},
    {"a": 2, "b": 2},
    {"a": 3, "b": 2}
]).compile(dialect=sqlite.dialect())


print t.insert().values([
    {t.c.a: 1, t.c.b: 2},
    {t.c.a: 2, t.c.b: 2},
    {t.c.a: 3, t.c.b: 2},
]).compile(dialect=sqlite.dialect())
</code></pre></div>
<p dir="auto">output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!

INSERT INTO t (a, b) VALUES (?, ?), (?, ?), (?, ?)
Traceback (most recent call last):
...
  File &quot;/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/crud.py&quot;, line 419, in _process_multiparam_default_bind
    &quot;a Python-side value or SQL expression is required&quot; % c)
sqlalchemy.exc.CompileError: INSERT value for column t.a is explicitly rendered as a boundparameter in the VALUES clause; a Python-side value or SQL expression is required
"><pre class="notranslate"><code class="notranslate">#!

INSERT INTO t (a, b) VALUES (?, ?), (?, ?), (?, ?)
Traceback (most recent call last):
...
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/crud.py", line 419, in _process_multiparam_default_bind
    "a Python-side value or SQL expression is required" % c)
sqlalchemy.exc.CompileError: INSERT value for column t.a is explicitly rendered as a boundparameter in the VALUES clause; a Python-side value or SQL expression is required

</code></pre></div>