我真的没想到这会起作用,但Android Room @Relation可以使用WHERE
子句进行过滤。例如:
SELECT * FROM meta WHERE subjectId IN (?)
@RawQuery(observedEntities = [ MetadataEntity::class, SubjectJunction::class ])
internal abstract fun internalGetImages(query: SupportSQLiteQuery): LiveData<List<MetadataXmp>>
`
data class MetadataXmp @JvmOverloads constructor(
@Embedded
val metadata:MetadataEntity,
@Relation(
parentColumn = "id",
entityColumn = "metaId",
projection = ["subjectId"],
entity = SubjectJunction::class)
var subjectIds: List<Long> = Collections.emptyList())
这会引发no such column: subjectId
。我怀疑@Relation
仅基于核心查询结果收集,并且关系列永远不会出现在初始查询中,但我想看看是否可以引用该关系。