Skip to content

Instantly share code, notes, and snippets.

@ManotLuijiu
Created April 2, 2025 04:58
Show Gist options
  • Save ManotLuijiu/7e7241bd5502508b2e603cd779a8850d to your computer and use it in GitHub Desktop.
Save ManotLuijiu/7e7241bd5502508b2e603cd779a8850d to your computer and use it in GitHub Desktop.
How to get Relations between Tables in ERPNext
bench --site your_site_name console
# Get all doctypes
doctypes = frappe.db.sql("SELECT name FROM `tabDocType` WHERE istable=0 AND issingle=0", as_dict=1)
# For each doctype, get link fields
for d in doctypes:
dt = frappe.get_meta(d.name)
links = dt.get_link_fields()
if links:
print(f"DocType: {d.name}")
for link in links:
print(f" → Links to {link.options} via field {link.fieldname}")
print("")
@ManotLuijiu
Copy link
Author

ManotLuijiu commented Apr 2, 2025

How to exit console:
type: exit()
then press "Enter" button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment