SQLAlchemy - Join condition fails with AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object has attribute 'selectable'


Eino Gourdin

I am running SQLAlchemy with Pyramid. I'm trying to run a query with a custom "join" condition:

DBSession.query(A)\
        .outerjoin(A.b, B.a_id == A.id)\
        .all()

But the query fails with the following error:

AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object has a 'selectable' attribute

The problem stemmed from the condition, as if I removed it, the query worked:

DBSession.query(A)\
        .outerjoin(A.b)\
        .all()

I don't understand the problem because I follow the syntax described in the documentation :

q = session.query(User).join(Address,User.id == Address.user_id)

Anyone see what's going on?

Eino Gourdin

OK, I see it. If you add a custom condition, the syntax is not .outerjoin(A.b, ...), but.outerjoin(B, ...)

They should accept both, really

(and the error message might be a bit more explicit)

Related


SQLAlchemy "AttributeError: 'str' object has no attribute 'c'"

WiGeeky: I have two tables named usersand permissionsI want to create a relationship between them using the specified table userPermissions. Here's what my code looks like: 类User(Base): __tablename__ ='用户' id =列(Integer,primary_key = True) first_

AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

AttributeError: 'SQLAlchemy' object has no attribute 'FieldType'

OK Python, flask and sqlalchemy newbies here. I am writing a small application to collect data (from an excel file) from different groups (departments). Each department will have associated tables and associated fields. Fields will have predefined types (numbe

AttributeError 'SQLAlchemy' object has no attribute 'create'

Sachin Mena I am trying to create a database using sqlalchemy and I am getting db.create.all()this error: File "<stdin>", line 1, in <module> AttributeError: 'SQLAlchemy' object has no attribute 'create' my code: from flask import Flask, render_template from

SQLAlchemy: AttributeError: 'table' object has no attribute 'id'

Yevgeny I am building a database that matches my local product catalog with foreign product catalogs. 'Catalog'SQLAlchemy works fine when I have only unique tables . After adding the tables Competitors, Competitors_catalogall attempts to add records to the two