-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
...c/test/kotlin/org/jetbrains/exposed/sql/tests/shared/entities/EntityBugsRegressionTest.kt
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,59 @@ | ||
@file: Suppress("MatchingDeclarationName", "Filename") | ||
package org.jetbrains.exposed.sql.tests.shared.entities | ||
|
||
import org.jetbrains.exposed.dao.EntityClass | ||
import org.jetbrains.exposed.dao.IntEntity | ||
import org.jetbrains.exposed.dao.IntEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.IdTable | ||
import org.jetbrains.exposed.sql.Column | ||
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase | ||
import org.jetbrains.exposed.sql.tests.shared.assertEquals | ||
import org.junit.Test | ||
|
||
class `Table id not in Record Test issue 1341` : DatabaseTestsBase() { | ||
|
||
object NamesTable : IdTable<Int>("names_table") { | ||
val first = varchar("first", 50) | ||
|
||
val second = varchar("second", 50) | ||
|
||
override val id = integer("id").autoIncrement().entityId() | ||
|
||
override val primaryKey = PrimaryKey(id) | ||
} | ||
|
||
object AccountsTable : IdTable<Int>("accounts_table") { | ||
val name = reference("name", NamesTable) | ||
override val id: Column<EntityID<Int>> = integer("id").autoIncrement().entityId() | ||
override val primaryKey = PrimaryKey(id) | ||
} | ||
|
||
class Names(id: EntityID<Int>) : IntEntity(id) { | ||
var first: String by NamesTable.first | ||
var second: String by NamesTable.second | ||
companion object : IntEntityClass<Names>(NamesTable) | ||
} | ||
|
||
class Accounts(id: EntityID<Int>) : IntEntity(id) { | ||
var name: Names by Names referencedOn AccountsTable.name | ||
|
||
companion object : EntityClass<Int, Accounts>(AccountsTable) { | ||
fun new(accountName: Pair<String, String>): Accounts = new { | ||
this.name = Names.new { | ||
first = accountName.first | ||
second = accountName.second | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun testRegression() { | ||
withTables(NamesTable, AccountsTable) { | ||
val account = Accounts.new("first" to "second") | ||
assertEquals("first", account.name.first) | ||
assertEquals("second", account.name.second) | ||
} | ||
} | ||
} |