Flask-SQLAlchemy,How to sort results in Many-to-Many Relationship?
<p>I am using flask-sqlalchemy.</p>

<p>I want to add an ORDER column in Many-to-Many Relationship.</p>

<p>my models:</p>

<pre><code>image_category_association = db.Table('category_image_relation',
    db.Column('id', db.Integer, primary_key=True),
    db.Column('category_id', db.Integer, db.ForeignKey('image_category.category_id')),
    db.Column('image_id', db.Integer, db.ForeignKey('image.image_id')),
    db.Column('order', db.Integer, unique=True, autoincrement=True)
)

class ImageCategory(db.Model):
    __bind_key__ = 'ads'
    __tablename__ = 'image_category'

    category_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255), default='')
    add_time = db.Column(db.Integer, default=0)
    images = db.relationship('Image', secondary=image_category_relation, backref='categories', lazy='dynamic')


class Image(db.Model):
    __bind_key__ = 'ads'
    __tablename__ = 'image'

    image_id = db.Column(db.Integer, primary_key=True)
    add_time = db.Column(db.Integer, default=0)
    hash = db.Column(db.String(64), default='')
    url = db.Column(db.String(255), default='')

category = ImageCategory.query.get(1)
category.images.append(image1, image2, image3)
images = category.images.all()  # order by the ORDER column
</code></pre>

<p>Is it possible to update the <strong>ORDER</strong> column value in table <strong>image_category_association</strong>?</p>

<p>And how do i sort the <strong>category.images.all()</strong> order by the <strong>ORDER</strong> column.</p>