I recently added Alembic to my Flask project and now my SQLAlchemy relationship sorting with order_by is no longer working. I believe this is because the migration file that is run is not picking up the order_by argument and I'm not sure how to get it in.
My model looks something like...
class Project(db.Model):
__tablename__ = 'project'
id = db.Column(db.Integer(), primary_key=True)
class User(db.Model):
__tablename__ = 'user'
id = db.Column(db.Integer(), primary_key=True)
project_id = db.Column(db.ForeignKey(Project.id, ondelete="cascade"), index=True, nullable=False)
project = db.relationship(Project, backref='members', order_by="User.id.desc()")
In the Alembic migration, I see the following...
...
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('project_id', sa.Integer(), nullable=False),
...
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ondelete='cascade'),
)
op.create_index(op.f('ix_user_project_id'), 'user', ['project_id'], unique=False)
...
Looking at the migration, I'm not quite sure how SQLAlchemy is actually handling the relationship since I don't see any sort of backref mentioned anywhere, I guess SQLAlchemy just runs a query to get a project's users.
Any help would be greatly appreciated!