Skip to content

Returning a subset of reverse FK #487

Answered by collerek
igormorgado asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, reverse FK expose QuerysetProxy which behaves like QuerySet (except it's pre-filtered for given parent model).
So you can construct all kinds of queries on relations too.

I.e.:

class User(ormar.Model):
    class Meta:
        tablename = "users"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    properties = ormar.JSON(nullable=True)


class Post(ormar.Model):
    class Meta:
        tablename = "posts"
        metadata = metadata
        database = database

    id: int = ormar.Integer(primary_key=True)
    name: str = ormar.String(max_length=100)
    created_by: Optional[User] = ormar.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by igormorgado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants