Say I have a model named User, and a tabled called followers:
followers = db.Table( 'followers', db.Column('follower_id', db.Integer, db.ForeignKey('user.id')), db.Column('followed_id', db.Integer, db.ForeignKey('user.id')) ) class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) followed = db.relationship( 'User', secondary=followers, primaryjoin=(followers.c.follower_id==id), secondaryjoin=(followers.c.followed_id==id), backref=db.backref('followers', lazy='dynamic'), lazy='dynamic' ) There are two ways to query the User model:
db.session.query(User).filter(...).all()User.query.filter(...).all()
The latter is considered a shorthand for the former, because they are functionally identical but it's more compact. However, when comes to the table,followers.query.filter(...).all() gives me an error:
AttributeError: 'Table' object has no attribute 'query'
Is there a shorthand for db.session.query(followers).filter(...).all()? or, how can I get a query object from a table object?