Sqlalchemy filter by field in list but keep original order?

后端 未结 4 1369
时光说笑
时光说笑 2021-02-12 22:35

I have a Shoe model like this:

class Shoe(db.Model):
id = db.Column(db.Integer, primary_key = True)
asin = db.Column(db.String(20), index = True)
4条回答
  •  情歌与酒
    2021-02-12 22:48

    What do you mean when you say "original order"? Database doesn't have such thing as "original order". If you need some order, you must add something like:

    .order_by(Shoe.id.desc())
    

    If you don't specify the order, it's still possible that you get ordered data from database. But in this case, database just uses order that doesn't needs any unnecessary data manipulation. It's just looks like an ordered data, but it isn't.

提交回复
热议问题