Skip to content

Commit

Permalink
fix: EXPOSED-646 count() voids distinctOn call on query (#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
obabichevjb authored Nov 29, 2024
1 parent 33376e0 commit 681bdb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ open class Query(override var set: FieldSet, where: Op<Boolean>?) : AbstractQuer
* @sample org.jetbrains.exposed.sql.tests.shared.dml.InsertSelectTests.testInsertSelect02
*/
override fun count(): Long {
return if (distinct || groupedByColumns.isNotEmpty() || limit != null || offset > 0) {
return if (distinct || distinctOn != null || groupedByColumns.isNotEmpty() || limit != null || offset > 0) {
fun Column<*>.makeAlias() =
alias(transaction.db.identifierManager.quoteIfNecessary("${table.tableNameWithoutSchemeSanitized}_$name"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,22 @@ class DistinctOnTests : DatabaseTestsBase() {
assertEquals(1, value)
}
}

@Test
fun testDistinctOnWithCount() {
val tester = object : IntIdTable() {
val name = varchar("name", 50)
}

withTables(excludeSettings = TestDB.ALL - distinctOnSupportedDb, tester) {
tester.batchInsert(listOf("tester1", "tester1", "tester2", "tester3", "tester2")) {
this[tester.name] = it
}

val count = tester.selectAll()
.withDistinctOn(tester.name)
.count()
assertEquals(3, count)
}
}
}

0 comments on commit 681bdb5

Please sign in to comment.