Android 初学者正在努力克服 Room Database 的这一限制。我正在使用两张桌子,“服装”和“服装”。用户可以通过插入提供给他们的值来创建服装。然后,在单独的页面上,用户可以插入带有他们已在 Clothing.kt 中创建的先前服装的服装。出于应用程序的考虑,关系只是一对多,这意味着我只需要使用许多服装项目创建一套服装。到目前为止,这是我的代码:
服装.kt
@Parcelize
@Entity(foreignKeys = [
ForeignKey(entity = Outfit::class,
parentColumns = ["id"],
childColumns = ["outfitRefFK"]
)
]
)
data class Clothing (
//Sets all attributes and primary key
@PrimaryKey(autoGenerate = true) val id: Int,
val type: String,
val color: String,
val style: String,
val description: String,
val dateAdded: Date = Date(),
val brand: String,
val theme: String,
val image: String,
@Nullable val outfitRefFK: Int
): Parcelable
Run Code Online (Sandbox Code Playgroud)
服装.kt
@Parcelize
@Entity
data class Outfit (
@PrimaryKey(autoGenerate …Run Code Online (Sandbox Code Playgroud)