Skip to content

ForeignKeyField with source_field argument #55

@krolikladoshka

Description

@krolikladoshka

Please, provide support for this feature. Currently ModelMeta metaclass ignores source_field for ForeignKey fields (just appends '_id' to field name). I've managed myself to fix this with one-liner directly inside tortoise-orm source code (can't create an abstract subclass of ModelMeta/Model, because Tortoise.init isn't setting _db field to all internal objects of orm), but this does not seem like a reliable fix.

Example where this can be helpful:

class Lambda(Model):
    id = fields.IntField(pk=True, null=False)

class Related(Model):
    lambda_ = fields.ForeignKeyField(
        'models.A',
        source_field='lambda'  # !
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions