Delete record from another doc(not a child table)

I have two docs
Doc1 and Doc2
when i submit Doc1 creating some entries and storing in Doc2
but i want to delete same entries from Doc2 when i cancel Doc1

how to do this?

What do you mean by creating some entries?

You can delete the docs if you have their name, use frappe.delete_doc(doctype, name)

Doc1 has one to many cardinality Doc2

  • in Doc1 view Doc2 is visible and also records can be added from same view i.e from Doc1 view itself.
  • there is a one to many realtion between Doc1(one) and Doc2(many).

Example Entry:
say for example Doc1 has 1 record R1D1.
Doc1: R1D1

which consist of multiple Doc2 records like given below

Doc2: R1D2
Doc2: R2D2
Doc2: R3D2

Now if I cancel R1D1, the below associated records should be deleted.

R1D2
R2D2
R3D2

You can write your logic in the on_trash method of Doc1 controller.

is it possible delete multiple rows? and how?