[Python] how to define a foreign key with pony entities

Discussão em 'Python' iniciado por Stack, Fevereiro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to define a foreign key with pony entities.

    If I understand it right, there is no need to define a primary key as long as it is named id. so the primary key of Jobs is id, and I want to define a foreign key job_id on Recipe which is related to id of Jobs. I tried Required(Jobs.id) but this gives a type error. do you have any hint on how to do it? thank you

    class Jobs(db.Entity):
    path = Required(str)
    date = Required(str)

    class Recipe(db.Entity):
    job_id = Required(int) # must be foreign
    path = OptionalField(str)
    date = OptionalField(str)

    Continue reading...

Compartilhe esta Página