房间里有外键在桌子上

时间:2019-02-26 13:51:53

标签: android kotlin android-room

我有2个实体,同人小说有一个章节列表:

@Entity
data class FanfictionEntity(
    @PrimaryKey val id: String,
    var title: String,
    var words: Int,
    var summary: String
)

@Entity(
    foreignKeys = [ForeignKey(
        entity = FanfictionEntity::class,
        parentColumns = ["id"],
        childColumns = ["fanfictionId"],
        onDelete = ForeignKey.CASCADE
    )]
)
data class ChapterEntity(
    @PrimaryKey(autoGenerate = true) val id: Long,
    val fanfictionId: String,
    val chapterId: String,
    val title: String,
    val content: String
)

DAO:

@Dao
interface FanfictionDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertFanfiction(fanfiction: FanfictionEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertChapterList(chapterList: List<ChapterEntity>)
}

问题是,当我尝试使用各章的插入内容进行构建时,gradle会引发错误。如果我发表评论,没问题。 在章节表中插入章节的方法是什么?

编辑:

我没有把ChapterEntity :: class:facepalm:

@Database(entities = [FanfictionEntity::class, ChapterEntity::class], version = 2)
abstract class FanfictionDownloaderDatabase : RoomDatabase() {
    abstract fun fanfictionDao(): FanfictionDao
}

0 个答案:

没有答案