How can I count and fetch records from a model in a single query with Tortoise-ORM? #1429
Unanswered
diegolatorre116
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an application in which I use Tortoise-orm to interact with a postgresql database. Then I have the following model:
As you can see, there is a one-to-many relationship between User and Dat. For a functionality of my application, I need to fetch all the records (applying an optional filter) from Dat together with the "name" field of the User table (which is related to Dat). But in addition, I apply an offset and limit, and I need to count also all the records (but without taking into account the offser and limit). So, I do it with the following approach:
My code works, but I have to do two queries to get what I want. Is there any way to do it with only one query?
Beta Was this translation helpful? Give feedback.
All reactions