Skip to content
Discussion options

You must be logged in to vote

You can specify sa_relationship_kwargs={"order_by": "UserRoomLink.created_at.desc()"} to your relationship attribute:

    rooms: List[Room] = Relationship(
        back_populates="users",
        link_model=UserRoomLink,
        sa_relationship_kwargs={
            "order_by": "UserRoomLink.created_at",
        },
    )

Try changing "order_by": "UserRoomLink.created_at" to "order_by": "UserRoomLink.created_at.desc()" and see that order will be different.

Runable code example in the details:

from datetime import datetime, timedelta
from typing import List, Optional
from sqlmodel import SQLModel, Field, Relationship, create_engine, Session


class UserRoomLink(SQLModel, table=True):
    ro…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Supreeth-Shetty
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
4 participants