'how to define a foreign key with pony entities

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)


Solution 1:[1]

I found the answer. the tricky thing is that the relationship had to be defined in both classes

class Jobs(db.Entity):
    path = Required(str)
    date = Required(str)
    jobs = Set("Recipe")

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Josh.h