Skip to content
Advertisement

Case in Sqlalchemy hybrid_property / expression error

I want to use expressions is ORM queries like this.

Profile.query.filter(Profile.complete).all()

Where complete is a calculated field

Sqlalchemy docs shows the below

So i’ve attempted to copy it with the following.

But the output sql query is as below – the case isn’t compared agaisnt anything.

So my output is all profiles, instead of only complete ones.

What am I doing wrong? I guess I don’t need to output a case?

Is there an easier solution? The actual SQL would be like this, but I don’t want to filter each field, I want to use the ORM to calculate the complete field automatically.

Advertisement

Answer

I made it work with

and_(cls.blurb != None, cls.services != None, cls.about != None, cls.name != None, cls.lat != None, cls.confirmed_tc == True)

Rather than using case

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement