'Setup query to update values for newly set fetch values'

def setup_fields_to_fetch(self):

    try:
        old_meta = frappe.get_meta(frappe.get_doc(u'DocType', self.name), cached=False)
        old_fields_to_fetch = [df.fieldname for df in old_meta.get_fields_to_fetch()]
    except frappe.DoesNotExistError:
        old_fields_to_fetch = []
    new_meta = frappe.get_meta(self, cached=False)
    self.flags.update_fields_to_fetch_queries = []
    if (set(old_fields_to_fetch) != set([df.fieldname for df in new_meta.get_fields_to_fetch()])):
        for df in new_meta.get_fields_to_fetch():
            if (df.fieldname not in old_fields_to_fetch):
                (link_fieldname, source_fieldname) = df.options.split(u'.', 1)
                link_df = new_meta.get_field(link_fieldname)
                self.flags.update_fields_to_fetch_queries.append(u'update\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB `tab{link_doctype}`    source,\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB `tab{doctype}`    target\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB set\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB target.`{fieldname}`    =    source.`{source_fieldname}`\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB where\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB target.`{link_fieldname}`    =    source.name\n DCTB  DCTB  DCTB  DCTB  DCTB  DCTB  DCTB and    ifnull(target.`{fieldname}`,    \'\')=""    '.format(link_doctype=link_df.options, source_fieldname=source_fieldname, doctype=self.name, fieldname=df.fieldname, link_fieldname=link_fieldname))
