fix: Use ORM instead of raw SQL

Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
Gavin D'souza 2020-11-30 12:03:53 +05:30
parent 147a3def0d
commit 29941ef46a

View file

@ -247,6 +247,7 @@ def update_link_field_values(link_fields, old, new, doctype):
pass
else:
parent = field['parent']
docfield = field["fieldname"]
# Handles the case where one of the link fields belongs to
# the DocType being renamed.
@ -258,11 +259,8 @@ def update_link_field_values(link_fields, old, new, doctype):
if parent == new and doctype == "DocType":
parent = old
frappe.db.sql("""
update `tab{table_name}` set `{fieldname}`=%s
where `{fieldname}`=%s""".format(
table_name=parent,
fieldname=field['fieldname']), (new, old))
frappe.db.set_value(parent, {docfield: old}, docfield, new)
# update cached link_fields as per new
if doctype=='DocType' and field['parent'] == old:
field['parent'] = new