Revert "fix(query): unique aliasing for linked field joins"
This commit is contained in:
parent
b011532a7e
commit
8b47c6e5a0
3 changed files with 7 additions and 12 deletions
|
|
@ -2087,7 +2087,8 @@ class LinkTableField(DynamicTableField):
|
||||||
|
|
||||||
def _get_joined_table(self):
|
def _get_joined_table(self):
|
||||||
table = frappe.qb.DocType(self.doctype)
|
table = frappe.qb.DocType(self.doctype)
|
||||||
table = table.as_(f"tab{self.doctype}_{self.link_fieldname}")
|
if self.doctype == self.parent_doctype:
|
||||||
|
table = table.as_(f"tab{self.doctype}_{self.link_fieldname}")
|
||||||
return table
|
return table
|
||||||
|
|
||||||
def apply_select(self, query: QueryBuilder, engine: "Engine" = None) -> QueryBuilder:
|
def apply_select(self, query: QueryBuilder, engine: "Engine" = None) -> QueryBuilder:
|
||||||
|
|
|
||||||
|
|
@ -1238,14 +1238,8 @@ class TestDBQuery(IntegrationTestCase):
|
||||||
fields=fields,
|
fields=fields,
|
||||||
).get_sql()
|
).get_sql()
|
||||||
|
|
||||||
self.assertIn(
|
self.assertIn("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_parent_ref`", query)
|
||||||
self.normalize_sql("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_parent_ref`"),
|
self.assertIn("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_sibling_ref`", query)
|
||||||
self.normalize_sql(query),
|
|
||||||
)
|
|
||||||
self.assertIn(
|
|
||||||
self.normalize_sql("LEFT JOIN `tabSelf Linked DocType` `tabSelf Linked DocType_sibling_ref`"),
|
|
||||||
self.normalize_sql(query),
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_select_star_expansion(self):
|
def test_select_star_expansion(self):
|
||||||
count = frappe.get_list("Language", [{"SUM": 1}, {"COUNT": "*"}], as_list=1, order_by=None)[0]
|
count = frappe.get_list("Language", [{"SUM": 1}, {"COUNT": "*"}], as_list=1, order_by=None)[0]
|
||||||
|
|
|
||||||
|
|
@ -371,10 +371,10 @@ class TestQuery(IntegrationTestCase):
|
||||||
fields=["name"],
|
fields=["name"],
|
||||||
filters={"module.app_name": "frappe"},
|
filters={"module.app_name": "frappe"},
|
||||||
).get_sql(),
|
).get_sql(),
|
||||||
"SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` `tabModule Def_module` ON `tabModule Def_module`.`name`=`tabDocType`.`module` WHERE `tabModule Def_module`.`app_name`='frappe'",
|
"SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` ON `tabModule Def`.`name`=`tabDocType`.`module` WHERE `tabModule Def`.`app_name`='frappe'",
|
||||||
)
|
)
|
||||||
|
|
||||||
query = "SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` `tabModule Def_module` ON `tabModule Def_module`.`name`=`tabDocType`.`module` WHERE `tabModule Def_module`.`app_name` LIKE 'frap%'"
|
query = "SELECT `tabDocType`.`name` FROM `tabDocType` LEFT JOIN `tabModule Def` ON `tabModule Def`.`name`=`tabDocType`.`module` WHERE `tabModule Def`.`app_name` LIKE 'frap%'"
|
||||||
query = query.replace("LIKE", "ILIKE" if frappe.db.db_type == "postgres" else "LIKE")
|
query = query.replace("LIKE", "ILIKE" if frappe.db.db_type == "postgres" else "LIKE")
|
||||||
self.assertQueryEqual(
|
self.assertQueryEqual(
|
||||||
frappe.qb.get_query(
|
frappe.qb.get_query(
|
||||||
|
|
@ -756,7 +756,7 @@ class TestQuery(IntegrationTestCase):
|
||||||
"DocType",
|
"DocType",
|
||||||
fields=["name", "module.app_name as app_name"],
|
fields=["name", "module.app_name as app_name"],
|
||||||
).get_sql(),
|
).get_sql(),
|
||||||
"SELECT `tabDocType`.`name`,`tabModule Def_module`.`app_name` `app_name` FROM `tabDocType` LEFT JOIN `tabModule Def` `tabModule Def_module` ON `tabModule Def_module`.`name`=`tabDocType`.`module`",
|
"SELECT `tabDocType`.`name`,`tabModule Def`.`app_name` `app_name` FROM `tabDocType` LEFT JOIN `tabModule Def` ON `tabModule Def`.`name`=`tabDocType`.`module`",
|
||||||
)
|
)
|
||||||
|
|
||||||
# fields now has strict validation, so this test is not valid anymore
|
# fields now has strict validation, so this test is not valid anymore
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue