SQLAlchemy query, join on relationship and order by count

前端 未结 1 834
遥遥无期
遥遥无期 2020-12-14 22:46

I have two SQLAlchemy models set up as follows:

##############
# Post Model #
##############
class Post(db.Model):
    id = db.Column(db.Integer, primary_key         


        
相关标签:
1条回答
  • 2020-12-14 23:43

    The translation from raw query to Flask-SQLAlchemy is pretty much mechanical:

    db.session.query(Post, db.func.count(Like.id)).outerjoin(Like).group_by(Post.id)
    
    0 讨论(0)
提交回复
热议问题