For example, this is how we can delete an order with the primary key equal to 123:

    Pony supports bulk delete for objects using the function. This way you can delete multiple objects without loading them to the cache:

    Note

    Cascade delete

    When Pony deletes an instance of an entity it also needs to delete its relationships with other objects. The relationships between two objects are defined by two relationship attributes. If another side of the relationship is declared as a Set, then we just need to remove the object from that collection. If another side is declared as Optional, then we need to set it to . If another side is declared as Required, we cannot just assign None to that relationship attribute. In this case, Pony will try to do a cascade delete of the related object.

    If the relationship is defined as at the other end and cascade_delete=False then Pony raises the ConstraintError exception on deletion attempt.

    Let’s consider a couple of examples.

    The example below raises the ConstraintError exception on an attempt to delete a group which has related students: