Skip to content

Commit

Permalink
#343 Table with composite key created only with specific prop order
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapac committed Jul 21, 2018
1 parent 7cf81c2 commit b8b5cb6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/kotlin/org/jetbrains/exposed/sql/Table.kt
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ open class Table(name: String = ""): ColumnSet(), DdlAware {
}

internal fun primaryKeyConstraint(): String? {
var pkey = columns.filter { it.indexInPK != null }.sortedBy { it.indexInPK }
var pkey = columns.filter { it.indexInPK != null }.sortedWith(compareBy({ !it.columnType.isAutoInc }, { it.indexInPK }))
if (pkey.isEmpty()) {
pkey = columns.filter { it.columnType.isAutoInc }
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/DDLTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ class DDLTests : DatabaseTestsBase() {
}
}

@Test fun tableWithMultiPKandAutoIncrement() {
val Foo = object : IdTable<Long>() {
val bar = integer("bar").primaryKey()
override val id: Column<EntityID<Long>> = long("id").entityId().autoIncrement().primaryKey()
}

withTables(Foo) {
Foo.insert {
it[Foo.bar] = 1
}
Foo.insert {
it[Foo.bar] = 2
}

val result = Foo.selectAll().map { it[Foo.id] to it[Foo.bar] }
assertEquals(2, result.size)
assertEquals(1, result[0].second)
assertEquals(2, result[1].second)
}
}

@Test fun testDefaults01() {
val currentDT = CurrentDateTime()
val nowExpression = object : Expression<DateTime>() {
Expand Down

0 comments on commit b8b5cb6

Please sign in to comment.