[Sqlalchemy-tickets] [sqlalchemy] #2797: expression-level many-to-one comparison
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-08-08 13:33:24
|
#2797: expression-level many-to-one comparison
-------------------------+---------------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: enhancement | Status: new
Priority: medium | Milestone: 0.9.0
Component: orm | Severity: minor - half an hour
Keywords: | Progress State: in queue
-------------------------+---------------------------------------
Just as `obj.many_to_one == some_object` works, it should do the right
thing if you say `obj.many_to_one == SomeClass`, which is actually
longhand notation for the "primaryjoin" but is consistent in other
systems.
this is in 0.9 so it gets noticed but should be OK for a backport to 0.8.
{{{
#!python
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
a_id = Column(Integer, ForeignKey('a.id'))
a = relationship("A")
s = Session()
# support this
# q1 = s.query(B).filter(B.a == A).exists()
# checks the argument, then just does this:
q1 = s.query(B).filter(B.a.expression).exists()
print s.query(A).filter(q1)
}}}
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2797>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|