You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(spatial): ensure correct table reference in select queries
Previously, queries using `select *` could lead to ambiguous column issues
in complex queries. This update ensures that all queries explicitly reference
the table name (`{table}.*`) to prevent conflicts and improve SQL clarity.
Additionally, test assertions have been updated to reflect this change.
Copy file name to clipboardexpand all lines: tests/HasSpatialTest.php
+5-5
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ public function it_generates_sql_query_for_selectDistanceTo_scope(): void
19
19
20
20
// Assert
21
21
$this->assertEquals(
22
-
expected: "select *, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr, ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) as distance from `addresses`",
22
+
expected: "select `addresses`.*, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr, ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) as distance from `addresses`",
23
23
actual: $query->toSql()
24
24
);
25
25
}
@@ -36,7 +36,7 @@ public function it_generates_sql_query_for_withinDistanceTo_scope(): void
36
36
37
37
// 3. Assert
38
38
$this->assertEquals(
39
-
expected: "select *, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses` where ST_AsText(location) != ? and ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) <= ?",
39
+
expected: "select `addresses`.*, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses` where ST_AsText(location) != ? and ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) <= ?",
40
40
actual: $query->toSql()
41
41
);
42
42
}
@@ -54,12 +54,12 @@ public function it_generates_sql_query_for_orderByDistanceTo_scope(): void
54
54
55
55
// 3. Assert
56
56
$this->assertEquals(
57
-
expected: "select *, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses` order by ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) asc",
57
+
expected: "select `addresses`.*, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses` order by ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) asc",
58
58
actual: $queryForAsc->toSql()
59
59
);
60
60
61
61
$this->assertEquals(
62
-
expected: "select *, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses` order by ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) desc",
62
+
expected: "select `addresses`.*, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses` order by ST_Distance(ST_SRID($castedAttr, ?), ST_SRID(Point(?, ?), ?)) desc",
63
63
actual: $queryForDesc->toSql()
64
64
);
65
65
}
@@ -73,7 +73,7 @@ public function it_generates_sql_query_for_location_casted_attributes(): void
73
73
74
74
// 2. Act & Assert
75
75
$this->assertEquals(
76
-
expected: "select *, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses`",
76
+
expected: "select `addresses`.*, CONCAT(ST_AsText(addresses.$castedAttr, 'axis-order=long-lat'), ',', ST_SRID(addresses.$castedAttr)) as $castedAttr from `addresses`",
0 commit comments