Many to many design solution

Hi!! Everyone,

My use case - I have customers which can be linked with suppliers and also suppliers which can be linked with customers.
Ex
Customer

  1. Jason
  2. Timothy

Supplier

  1. Wholesale produce
  2. Organic worldwide
  3. Nutro produce

Many - 2 -many link

  1. Jason - Wholesale produce
  2. Timothy - Wholesale produce
  3. Jason - Nutro produce
    Also, in above relation it has to be unique i.e. say new entry Jason - Wholesale produce cannot be done as it is already there

My question

  • do we have any good such many-2-many implemented in any ERPNext existing doctypes etc
  • What should be the best approach for this?
    Thanks!

Solution -
It is based on address/contact the way they linked with customer

Insert dynamic link in supplier doctype-- to store linked customer name

And in customer py write a function to insert record in supplier–dynamic link table

def make_supplier(args):
if args.get(‘supplier’)!=None:
supplier=frappe.get_doc(‘Supplier’, args.get(‘supplier’))
supplier.append(‘links’, dict(link_doctype=‘Customer’, link_name=args.get(‘name’)))
supplier.save()
return supplier