Closed Prof1-web closed 11 months ago
Describe the bug Query set api https://tortoise.github.io/query.html#tortoise.queryset.QuerySet.only only() doesn't work with values()
To Reproduce
class Request(Model): id = fields.BigIntField(pk=True) first_name = fields.CharField(255) last_name = fields.CharField(255, null=True) user = fields.ForeignKeyField("models.User") approved = fields.BooleanField(default=False) created_at = fields.DatetimeField(auto_now_add=True) print(Request.all().only("id").sql()) print(Request.all().only("id").values().sql()) # SELECT "id" "id" FROM "request" # SELECT "id" "id","first_name" "first_name","last_name" "last_name","approved" "approved","created_at" "created_at","user_id" "user_id" FROM "request"
Expected behavior I expect that first and second sql queries to be equal, but in second case tortoise loads all the fields from the db
Ok, I found solution:
print(Request.all().values("id").sql())
It works, but documentation needs to be changed, it's not obvious
Describe the bug Query set api https://tortoise.github.io/query.html#tortoise.queryset.QuerySet.only only() doesn't work with values()
To Reproduce
Expected behavior I expect that first and second sql queries to be equal, but in second case tortoise loads all the fields from the db