forked from serverpod/serverpod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: truncate query aliases generated by the table relation class use…
…d for joins and sub queries.
- Loading branch information
Showing
2 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/serverpod/test/database/database_query/long_relation_field_name/join_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:serverpod/database.dart'; | ||
import 'package:serverpod/src/database/database_query.dart'; | ||
import 'package:serverpod/test_util/table_relation_builder.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
var citizenTable = Table(tableName: 'citizen'); | ||
var companyTable = Table(tableName: 'company'); | ||
var relationTable = TableRelationBuilder(companyTable).withRelationsFrom([ | ||
BuilderRelation( | ||
citizenTable, | ||
'thisFieldIsExactly61CharactersLongAndIsThereforeValidAsNameFo', | ||
), | ||
]).build(); | ||
|
||
group('Given SelectQueryBuilder', () { | ||
group('when filtering causes a long join name.', () { | ||
var query = SelectQueryBuilder(table: citizenTable) | ||
.withWhere(relationTable.id.equals(1)) | ||
.build(); | ||
|
||
test('then join query name is truncated.', () { | ||
expect( | ||
query, | ||
contains( | ||
'LEFT JOIN "company" AS "citizen_thisFieldIsExactly61CharactersLongAndIsThereforeVale9b4"'), | ||
); | ||
}); | ||
|
||
test('then join query uses the truncated join name.', () { | ||
expect( | ||
query, | ||
contains( | ||
'"citizen"."id" = "citizen_thisFieldIsExactly61CharactersLongAndIsThereforeVale9b4"."id"'), | ||
); | ||
}); | ||
|
||
test('then uses truncated name in where statements in for join.', () { | ||
expect( | ||
query, | ||
contains( | ||
'"citizen_thisFieldIsExactly61CharactersLongAndIsThereforeVale9b4"."id" = 1'), | ||
); | ||
}); | ||
}); | ||
}); | ||
} |