我需要在房间中使用@relation anion 来三重加入我的实体,但我不知道如何。
这是我对实体的总结:
@Entity(tableName = "session_table")
data class Session(
@PrimaryKey(autoGenerate = true)
var sessionId: Long = 0L,
@ColumnInfo(name = "lesson_id")
var lessonId: Long
)
@Entity(tableName = "lessons_table")
data class Lesson(
@PrimaryKey(autoGenerate = true)
val lessonId: Long,
@ColumnInfo(name = "teacher_id")
var teacherId: Long = -1L
)
@Entity(tableName = "teacher_table")
data class Teacher(
@PrimaryKey(autoGenerate = true)
val teacherId: Long = 0L
)
我认为答案是这样的:
data class SessionWithLessonWithTeacher(
@Embedded
val session: Session,
@Relation(
parentColumn = "lesson_id",
entityColumn = "lessonId"
)
var lesson: Lesson,
@Relation(
parentColumn = "teacher_id", // this is the teacher id in lesson
entityColumn = "teacherId",
)
var teacher: Teacher
)