<h3 dir="auto"><strong>update</strong> - for real ORM upsert, please see SQLAlchemy 2.0's new feature at <a href="https://docs.sqlalchemy.org/en/20/orm/queryguide/dml.html#orm-upsert-statements" rel="nofollow">https://docs.sqlalchemy.org/en/20/orm/queryguide/dml.html#orm-upsert-statements</a></h3>
<p dir="auto">Currently there is no way to specify <code class="notranslate">on conflict</code> behaviour when using <code class="notranslate">session</code> class and it's <code class="notranslate">add</code> method which makes a decision to either <code class="notranslate">insert</code> or <code class="notranslate">update</code>.<br>
This would be a nice addition to have <code class="notranslate">on conflict</code> behaviour of this method configurable.</p>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">Let's consider the example given in the documentation.<br>
One can do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="s.query(User).filter(User.user_keywords.contains(user_keyword))"><pre class="notranslate"><code class="notranslate">s.query(User).filter(User.user_keywords.contains(user_keyword))
</code></pre></div>
<p dir="auto">but he can't do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="s.query(User).filter(User.keywords.contains(keyword))"><pre class="notranslate"><code class="notranslate">s.query(User).filter(User.keywords.contains(keyword))
</code></pre></div>
<p dir="auto">because:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="AttributeError: 'AssociationProxy' object has no attribute 'contains'"><pre class="notranslate"><code class="notranslate">AttributeError: 'AssociationProxy' object has no attribute 'contains'
</code></pre></div>
<p dir="auto">That's why, when I use the association_proxy pattern, I also add another view only relation between the two referenced objects (in this case User and Keyword), using the secondary table.<br>
I use this relation for selecting, and I use the association_proxy relation for inserting...</p>
<p dir="auto">This duplication is annoying. I don't know if it's possible to solve the problem, but I want to be able to do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="s.query(User).filter(User.keywords.contains(keyword))"><pre class="notranslate"><code class="notranslate">s.query(User).filter(User.keywords.contains(keyword))
</code></pre></div>
<p dir="auto"><a href="mailto:kobipe3@gmail.com">kobipe3@gmail.com</a></p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/1372/ticket-1372-associationproxy-comparators.patch">ticket-1372-associationproxy-comparators.patch</a></p>