Closed
Description
Migrated issue, originally created by Anonymous
Let's consider the example given in the documentation.
One can do:
s.query(User).filter(User.user_keywords.contains(user_keyword))
but he can't do:
s.query(User).filter(User.keywords.contains(keyword))
because:
AttributeError: 'AssociationProxy' object has no attribute 'contains'
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.
I use this relation for selecting, and I use the association_proxy relation for inserting...
This duplication is annoying. I don't know if it's possible to solve the problem, but I want to be able to do:
s.query(User).filter(User.keywords.contains(keyword))
Attachments: ticket-1372-associationproxy-comparators.patch
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Apr 6, 2009
Anonymous wrote:
submitted by kobipe3@gmail.com
sqlalchemy-bot commentedon Apr 6, 2009
Michael Bayer (@zzzeek) wrote:
it is possible using a comparable_property mapping to your descriptor:
http://www.sqlalchemy.org/docs/05/reference/orm/mapping.html#sqlalchemy.orm.comparable_property
build a Comparator and implement the comparison methods you'd like and they will be assembled on your associationproxy.
im wondering how hard it would be to build this into associationproxy directly.
sqlalchemy-bot commentedon Apr 6, 2009
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Apr 6, 2009
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Oct 17, 2009
Anonymous wrote:
I wanted to use the has and any functions on associationproxies, and didn't know about about comparable_property, so I added this to AssociationProxy:
I'll try using a comparable_property instead now, but if it's possible to implement a general solution for AssociationProxy, I'd be willing to try to figure out the other Comparator functions.
sqlalchemy-bot commentedon Nov 18, 2009
Anonymous wrote:
Here's a patch against 26edef4 that adds proxying of .any(), .has(), .contains(), ==, and != to association_proxies. Lots of tests are included.
Any thoughts on whether or not this implementation is appropriate?
Also, please add storborg@mit.edu to the cc list on this ticket. Thanks!
sqlalchemy-bot commentedon Nov 18, 2009
Anonymous wrote:
(original author: ged)
sqlalchemy-bot commentedon Jan 18, 2010
Michael Bayer (@zzzeek) wrote:
hey this is a great patch. We just have to work the unittest to use
MappedTest
,Comparable
andeq_
(at the very least speeds up the test to only setup/teardown once for the whole suite) and its good to go.sqlalchemy-bot commentedon Jan 18, 2010
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Jan 22, 2010
Michael Bayer (@zzzeek) wrote:
Scott, you are the man. this is in 2d15d9b thanks !
sqlalchemy-bot commentedon Jan 22, 2010
Changes by Michael Bayer (@zzzeek):