Open YAGregor opened 8 months ago
btw, I don't think F extend pypika's field is a good idea,I tried to implement this feature but seem its hard to extend feature.
Is your code struct imitate Django ORM? I suggest to organize query like tree, and "dump" the tree recursively just like peewee
Have you find a solution or an alternative approach to the problem?
I'm facing a similar issue. Trying to refer foreign key model's field. Following snippet didn't yield any result:
class Stop(Model):
stop_id = fields.IntField(pk=True)
stop_code = fields.CharField(max_length=32)
stop_name = fields.CharField(max_length=255)
class StopTime(Model):
stop: fields.ForeignKeyRelation['Stop'] = fields.ForeignKeyField(
model_name='models.Stop',
related_name='stop_times',
source_field='stop_id'
)
record = await StopTime.select_related('stop').annotate(stop_name=F('stop__stop_name').first()
print(record.stop_name)
Have you find a solution or an alternative approach to the problem?
I'm facing a similar issue. Trying to refer foreign key model's field. Following snippet didn't yield any result:
class Stop(Model): stop_id = fields.IntField(pk=True) stop_code = fields.CharField(max_length=32) stop_name = fields.CharField(max_length=255) class StopTime(Model): stop: fields.ForeignKeyRelation['Stop'] = fields.ForeignKeyField( model_name='models.Stop', related_name='stop_times', source_field='stop_id' ) record = await StopTime.select_related('stop').annotate(stop_name=F('stop__stop_name').first() print(record.stop_name)
no, I think it's almost impossible, to implement this, its code need a big refactor
Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
to reproduce:
Describe the solution you'd like A clear and concise description of what you want to happen.
F() be able to reference fields of foreign key's model
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Add any other context about the feature request here.