Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

SQLAlchemy ordering by count on a many to many relationship

db.session.query(Post, func.count(likes.c.user_id).label('total')).join(likes).group_by(Post).order_by('total DESC')
 
PREVIOUS NEXT
Tagged: #SQLAlchemy #ordering #count #relationship
ADD COMMENT
Topic
Name
3+9 =