Skip to content

Commit

Permalink
EXPOSED-387 Exposed Join.lastQueryAlias not working correctly (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
obabichevjb committed May 17, 2024
1 parent 00b9440 commit 4a6e298
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fun Table.joinQuery(on: (SqlExpressionBuilder.(QueryAlias) -> Op<Boolean>), join
* @sample org.jetbrains.exposed.sql.tests.shared.AliasesTests.testJoinSubQuery02
*/
val Join.lastQueryAlias: QueryAlias?
get() = joinParts.map { it.joinPart as? QueryAlias }.firstOrNull()
get() = joinParts.mapNotNull { it.joinPart as? QueryAlias }.lastOrNull()

/**
* Wraps a [query] as an [Expression] so that it can be used as part of an SQL statement or in another query clause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ class AliasesTests : DatabaseTestsBase() {
}
}

@Test
fun testJoinSubQuery03() {
withCitiesAndUsers { cities, users, userData ->
val firstJoinQuery = cities
.leftJoin(users)
.joinQuery(
on = { it[userData.user_id] eq users.id },
joinPart = { userData.selectAll() }
)
assertEquals("q0", firstJoinQuery.lastQueryAlias?.alias)

val secondJoinQuery = firstJoinQuery.joinQuery(
on = { it[userData.user_id] eq users.id },
joinPart = { userData.selectAll() }
)
assertEquals("q1", secondJoinQuery.lastQueryAlias?.alias)
}
}

@Test
fun testWrapRowWithAliasedTable() {
withTables(EntityTestsData.XTable, EntityTestsData.YTable) {
Expand Down

0 comments on commit 4a6e298

Please sign in to comment.