我想知道在使用录音表时如何从类别名称访问类别名称
//我想在使用ExpreCord时访问适配器和ViewModel中的类别名称,而不必在ExpreCord类中添加名称
@Entity(tableName = "Category")
data class ExpCategory(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(name = "category-name") val name: String )
@Entity(tableName = "Currency")
data class Currency(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(name = "symbol") val symbol: String )
@Entity(tableName = "Record",
foreignKeys = [ ForeignKey(
entity = ExpCategory::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("expCategoryID"),
onDelete = ForeignKey.SET_NULL),
ForeignKey(
entity = Currency::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("currencyID"),
onDelete = ForeignKey.SET_NULL)])
data class ExpRecord (
@PrimaryKey(autoGenerate = true) val recordNumber: Int,
@ColumnInfo(name = "expCategoryID") val categoryId: Int,
@ColumnInfo(name = "currencyID") val currencyId: Int,
@ColumnInfo(name = "amount") val amount: Double,
@ColumnInfo(name = "date") val date: String,
@ColumnInfo(name = "notes") val note: String )
//I want to access name of category in the adapter and viewModel while working with ExpRecord without having to add name in ExpRecord class
@Entity(tableName = "Category")
data class ExpCategory(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(name = "category-name") val name: String )
@Entity(tableName = "Currency")
data class Currency(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(name = "symbol") val symbol: String )
@Entity(tableName = "Record",
foreignKeys = [ ForeignKey(
entity = ExpCategory::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("expCategoryID"),
onDelete = ForeignKey.SET_NULL),
ForeignKey(
entity = Currency::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("currencyID"),
onDelete = ForeignKey.SET_NULL)])
data class ExpRecord (
@PrimaryKey(autoGenerate = true) val recordNumber: Int,
@ColumnInfo(name = "expCategoryID") val categoryId: Int,
@ColumnInfo(name = "currencyID") val currencyId: Int,
@ColumnInfo(name = "amount") val amount: Double,
@ColumnInfo(name = "date") val date: String,
@ColumnInfo(name = "notes") val note: String )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以通过使用Daos查询多个表,从而可以。参见访问多个表数据
Thats possible by querying multiple tables using Room DAOs. See accessing multiple table data