tortoise-orm icon indicating copy to clipboard operation
tortoise-orm copied to clipboard

use only for nested model fields

Open falled10 opened this issue 4 years ago • 4 comments

Hi There!

How to make only for nested model fields Example:

class A:
    id = fields.IntField()
    name = fields.CharField()
    other_field = fields.CharField()

class B:
    id = fields.IntField()
    b_name = fields.CharField()
    a = fields.ForeignKeyField('models.A', related_name='Bs', on_delete=fields.CASCADE)
    
    
B.all().select_related('a').only('id', 'b_name', 'a__name')

This example will throw

KeyError: 'a__name'

falled10 avatar Sep 20 '21 10:09 falled10

Current you can use .values

long2ice avatar Sep 22 '21 02:09 long2ice

@long2ice this won't help if you want to use pydantic schemas :(

falled10 avatar Sep 23 '21 07:09 falled10

i need it too.

oyish avatar Nov 14 '21 18:11 oyish

This feature could be useful in our project.

Qlas avatar Sep 12 '24 13:09 Qlas