[Sqlalchemy-tickets] Issue #4302: startswith is a comparison (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: Charles Bouchard-L. <iss...@bi...> - 2018-07-10 17:41:30
|
New issue 4302: startswith is a comparison https://bitbucket.org/zzzeek/sqlalchemy/issues/4302/startswith-is-a-comparison Charles Bouchard-Legare: Since startswith is a kind of like and like is a comparison, startswith should be too. This would enable startswith-based custom join conditions without the use of a custom op. Without it, I get: ``` sqlalchemy.exc.ArgumentError: Relationship Order.project could not determine any unambiguous local/remote column pairs based on join condition and remote_side arguments. Consider using the remote() annotation to accurately mark those elements of the join condition that are on the remote side of the relationship. ``` To reproduce, try the following models: ``` #!python class Project(Base): __tablename__ = 'project' id = Column(Integer, primary_key=True) name = Column(String) class Order(Base): __tablename__ = 'order' id = Column(Integer, primary_key=True) project_name = Column(String) project = relationship( 'Project', primaryjoin='Order.project_name.startswith(foreign(Project.name))', viewonly=True ) ``` Workaround : ``` #!python from sqlalchemy.sql import operators operators._comparison.add(operators.startswith_op) ``` Test case could look like ``` #!python def test(): assert operators.is_comparison(operators.startswith_op) ``` |