Skip to content

Commit

Permalink
fix: remove base table validation for inner where on count columns
Browse files Browse the repository at this point in the history
  • Loading branch information
SandPod committed Oct 10, 2023
1 parent 278674e commit a6a9d84
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
16 changes: 0 additions & 16 deletions packages/serverpod/lib/src/database/database_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -515,22 +515,6 @@ void _validateTableReferences(
.add('"orderBy" expression referencing column $column.');
}
}

var innerWhereColumns = orderBy.expand<Column>((order) {
var column = order.column;
if (column is! ColumnCount) {
return [];
}

return column.innerWhere?.columns ?? [];
});

for (var column in innerWhereColumns) {
if (!column.hasBaseTable(tableName)) {
exceptionMessages
.add('"orderBy" expression referencing column $column.');
}
}
}

if (where != null) {
Expand Down
21 changes: 1 addition & 20 deletions packages/serverpod/test/database/database_query_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,7 @@ void main() {
});

test(
'when inner where for order by has different table as base then exception is thrown.',
() {
var queryBuilder = SelectQueryBuilder(table: citizenTable).withOrderBy([
Order(
column: ColumnCount(
companyTable.id.equals(5), citizenTable, citizenTable.id))
]);

expect(
() => queryBuilder.build(),
throwsA(isA<FormatException>().having(
(e) => e.toString(),
'message',
equals(
'FormatException: Column references starting from other tables than "citizen" are not supported. The following expressions need to be removed or modified:\n"orderBy" expression referencing column "company"."id".'),
)));
});

test(
'when count column is used in where expression then exception is thrown.',
'when count column is used in where expression then exception is thrown.',
() {
var countColumn =
ColumnCount(citizenTable.id.equals(5), citizenTable, citizenTable.id);
Expand Down

0 comments on commit a6a9d84

Please sign in to comment.