我想知道在使用录音表时如何从类别名称访问类别名称

发布于 2025-02-03 14:41:16 字数 1162 浏览 2 评论 0原文

//我想在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉南桥 2025-02-10 14:41:16

可以通过使用Daos查询多个表,从而可以。参见访问多个表数据

Thats possible by querying multiple tables using Room DAOs. See accessing multiple table data

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文