diff --git a/core/models/locations.go b/core/models/locations.go index d23c91fec..23701b913 100644 --- a/core/models/locations.go +++ b/core/models/locations.go @@ -125,20 +125,20 @@ SELECT SELECT DISTINCT(a.name) FROM - locations_boundaryalias a + locations_locationalias a WHERE - a.boundary_id = l.id AND + a.location_id = l.id AND a.is_active = TRUE AND a.org_id = $1 ORDER BY a.name )a ) aliases FROM - locations_adminboundary l + locations_location l WHERE - l.lft >= (select lft from locations_adminboundary la, orgs_org o where la.id = o.country_id and o.id = $1) and - l.rght <= (select rght from locations_adminboundary la, orgs_org o where la.id = o.country_id and o.id = $1) and - l.tree_id = (select tree_id from locations_adminboundary la, orgs_org o where la.id = o.country_id and o.id = $1) + l.lft >= (select lft from locations_location la, orgs_org o where la.id = o.location_id and o.id = $1) and + l.rght <= (select rght from locations_location la, orgs_org o where la.id = o.location_id and o.id = $1) and + l.tree_id = (select tree_id from locations_location la, orgs_org o where la.id = o.location_id and o.id = $1) ORDER BY l.level, l.id; ` diff --git a/core/models/locations_test.go b/core/models/locations_test.go index e3cea37cd..09601ba81 100644 --- a/core/models/locations_test.go +++ b/core/models/locations_test.go @@ -15,12 +15,12 @@ import ( func TestLocations(t *testing.T) { ctx, rt := testsuite.Runtime() - defer rt.DB.MustExec(`DELETE FROM locations_boundaryalias WHERE created_by_id = 2`) + defer rt.DB.MustExec(`DELETE FROM locations_locationalias WHERE created_by_id = 2`) - rt.DB.MustExec(`INSERT INTO locations_boundaryalias(is_active, created_on, modified_on, name, boundary_id, created_by_id, modified_by_id, org_id) - VALUES(TRUE, NOW(), NOW(), 'Soko', 8148, 2, 1, 1);`) - rt.DB.MustExec(`INSERT INTO locations_boundaryalias(is_active, created_on, modified_on, name, boundary_id, created_by_id, modified_by_id, org_id) - VALUES(TRUE, NOW(), NOW(), 'Sokoz', 8148, 2, 1, 2);`) + rt.DB.MustExec(`INSERT INTO locations_locationalias(is_active, created_on, modified_on, name, location_id, created_by_id, modified_by_id, org_id) + VALUES(TRUE, NOW(), NOW(), 'Soko', 987, 2, 1, 1);`) + rt.DB.MustExec(`INSERT INTO locations_locationalias(is_active, created_on, modified_on, name, location_id, created_by_id, modified_by_id, org_id) + VALUES(TRUE, NOW(), NOW(), 'Sokoz', 987, 2, 1, 2);`) oa, err := models.GetOrgAssetsWithRefresh(ctx, rt, testdata.Org1.ID, models.RefreshLocations) require.NoError(t, err) diff --git a/testsuite/testfiles/postgres.dump b/testsuite/testfiles/postgres.dump index 24f54f373..ae9619292 100644 Binary files a/testsuite/testfiles/postgres.dump and b/testsuite/testfiles/postgres.dump differ