fix: frappe.db.field_exists

- field_exists didn't work correctly
- The call to field_exists itself was wrong
This commit is contained in:
Faris Ansari 2019-09-19 15:41:17 +05:30
parent 814b29923f
commit c8a80a2e4d
2 changed files with 6 additions and 3 deletions

View file

@ -758,7 +758,10 @@ class Database(object):
def field_exists(self, dt, fn):
"""Return true of field exists."""
return self.sql("select name from tabDocField where fieldname=%s and parent=%s", (dt, fn))
return self.exists('DocField', {
'fieldname': fn,
'parent': dt
})
def table_exists(self, doctype):
"""Returns True if table for given doctype exists."""

View file

@ -38,8 +38,8 @@ def get_controller(doctype):
or ["Core", False]
if custom:
if frappe.db.field_exists(doctype, "is_tree"):
is_tree = frappe.db.get_value("DocType", doctype, ("is_tree"), cache=True)
if frappe.db.field_exists("DocType", "is_tree"):
is_tree = frappe.db.get_value("DocType", doctype, "is_tree", cache=True)
else:
is_tree = False
_class = NestedSet if is_tree else Document