Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Kotlin中实现表继承?_Kotlin_Kotlin Exposed - Fatal编程技术网

如何在Kotlin中实现表继承?

如何在Kotlin中实现表继承?,kotlin,kotlin-exposed,Kotlin,Kotlin Exposed,例如: 我有一个名为Pet的基本表,其中包含生日和名称列 我还有两个表是从这个表派生出来的,一个叫做PetDog表,列为numberofteaths,另一个叫做PetBird表,列为bikecolor 如何使用Kotlin Exposed实现这一点 或者有关于这方面的文档吗?您想要什么样的数据库和模式?它如何支持表继承?如评论中所述,关系数据库的常用方法是使用一个表和所有列或两个表(pet和dog,以某种方式将两个表中的记录相互链接) 有两个表的简单示例: create table pet (i

例如:

我有一个名为Pet的基本表,其中包含
生日
名称

我还有两个表是从这个表派生出来的,一个叫做PetDog表,列为
numberofteaths
,另一个叫做PetBird表,列为
bikecolor

如何使用Kotlin 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")
}

PetDog
表应该有3列(
BirthDate
Name
numberoftooth
)?或者它应该有两列(
BirthDate
PetId
),其中
PetId
指向
Pet
表中的某一行?换句话说,使用组合而不是继承。但是,我不会使宠物引用为空。;)@TimvanderLeeuw谢谢你的评论,我同意。我已将
pet_id
更改为不可为空的字段。