【发布时间】:2020-11-12 00:37:01
【问题描述】:
我有两个表 sites 和 groups 具有类似的数据类
@Entity(tableName = "sites")
data class Site(
@PrimaryKey
@ColumnInfo(name = "site_id")
val siteId: Int,
@ColumnInfo(name = "description", defaultValue = "")
val description: String
)
@Entity(tableName = "groups")
data class Group(
@PrimaryKey
@ColumnInfo(name = "group_id")
var groupId: Int,
@ColumnInfo(name = "site_id")
val siteId: Int,
@ColumnInfo(name = "description", defaultValue = "")
val description: String
)
所以我们可以看到每个站点都有一个组列表。
我想要的是,给定 site_id 和 group_id 我怎么能得到这样的结果呢
class SiteGroup {
@Embedded
var site: Site? = null
@Relation(parentColumn = "site_id", entityColumn = "site_id", entity = Group::class)
var groups: Group? = null
}
我已经尝试了以下
@Query("""Select * from sites
inner join groups on groups.site_id = :siteId
where site_id = :siteId and groups.group_id = :groupId
""")
fun getByIdWithGroup(siteId: Int, groupId: Int): LiveData<SiteGroup>
但我在构建时遇到以下异常
error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (ambiguous column name: site_id)
public abstract androidx.lifecycle.LiveData<com.example.model.entities.pojos.SiteGroup> getByIdWithGroups(int siteId, int groupId)
Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
【问题讨论】:
标签: android sqlite kotlin android-room pojo