示例:
我有一个基础表称为Pet,包含BirthDate
和Name
列。
我有两个从该表派生的表,一个称为PetDog表,包含NumberOfTeeth
列,另一个称为PetBird表,包含BeakColor
列。
如何使用Kotlin Exposed实现这个?https://github.com/JetBrains/Exposed
或者是否有相关文档可供参考?
示例:
我有一个基础表称为Pet,包含BirthDate
和Name
列。
我有两个从该表派生的表,一个称为PetDog表,包含NumberOfTeeth
列,另一个称为PetBird表,包含BeakColor
列。
如何使用Kotlin Exposed实现这个?https://github.com/JetBrains/Exposed
或者是否有相关文档可供参考?
pet
和dog
,并且有某种方法将两个表中的记录链接起来)。create table pet (id int auto_increment primary key, birthdate varchar(10) not null, "name" varchar(50) not null)
create table dog (id int auto_increment primary key, pet_id int not null, number_of_teeth int not null, constraint fk_dog_pet_id_id foreign key (pet_id) references pet(id) on delete restrict on update restrict)
您的暴露表定义代码可能如下所示:
object Pet : IntIdTable() {
val birthdate = varchar("birthdate", 10)
val name = varchar("name", 50)
}
object Dog : IntIdTable() {
val petId = reference("pet_id", Pet).nullable()
val numberOfTeeth = integer("number_of_teeth")
}
pet_id
更改为非空字段。 - Freek de Bruijn
PetDog
表应该有3列(BirthDate
,Name
,NumberOfTeeth
)吗?还是它应该只有2列(BirthDate
,PetId
),其中PetId
指向Pet
表中的某一行? - Михаил Нафталь