micro-service,multi-databases,multi-tables...DBA said it does not recommend the use of foreign keys.
How to write the code?
object Users : Table() {
val id = varchar("id", 10).primaryKey() // Column<String>
val name = varchar("name", length = 50) // Column<String>
val cityId = (integer("city_id") references Cities.id).nullable() // Column<Int?>
}
object Cities : Table() {
val id = integer("id").autoIncrement().primaryKey() // Column<Int>
val name = varchar("name", 50) // Column<String>
}
I do not quite understand what do you mean by "not recommend" and what code do you want to write?
For example, User table and bank table is a one-to-one relationship.However, the number of users soared, we need to split the user table. At this point, the foreign key will bring great troubles to the DBA.
So, I want to remove the foreign key.
eg.
object Users : Table() {
val id = varchar("id", 10).primaryKey() // Column<String>
val name = varchar("name", length = 50) // Column<String>
//val cityId = (integer("city_id") references Cities.id).nullable() // before modification
val cityId = integer("city_id").nullable()
}
object Cities : Table() {
val id = integer("id").autoIncrement().primaryKey() // Column<Int>
val name = varchar("name", 50) // Column<String>
}
Just don't use references and manage everything manually.
val cityId = integer("city_id").entityId().nullable()
Most helpful comment
Just don't use references and manage everything manually.
val cityId = integer("city_id").entityId().nullable()