I'm having issues creating @Relation. I previously was using a complicated query to handle M:N, but I wanted to try the simpler @Relation and rely on ids. However, I get an error whenever I extend or embed the @Relation class. This works:
@Entity(tableName = "meta",
foreignKeys = [ForeignKey(
entity = FolderEntity::class,
parentColumns = ["id"],
childColumns = ["parentId"],
onDelete = CASCADE)],
indices = [
Index(value = ["uri"], unique = true),
Index(value = ["documentId"], unique = true),
Index(value = ["parentId"])])
open class MetadataEntity {
@PrimaryKey(autoGenerate = true)
var id: Long = 0
...
}
@TypeConverters(MetadataResult::class)
class MetadataResult : MetadataEntity() {
var keywords: List<String>? = null
var parentUri: String? = null
@TypeConverter
fun fromGroupConcat(keywords: String?): List<String>? = keywords?.split(",")
}
However, this does not work:
data class MetadataXmp(
@Embedded
val metadata:MetadataEntity,
@Relation(
parentColumn = "id",
entityColumn = "metaId",
projection = ["subjectId"],
entity = SubjectJunction::class)
var subjectIds: List<Long> = Collections.emptyList(),
@Relation(
parentColumn = "parentId",
entityColumn = "id",
projection = ["documentUri"],
entity = FolderEntity::class)
var parentUris: List<String> = Collections.emptyList())
Please note that the varying object type (class, data class, etc) is just the state of disarray of my attempts. I have tried various versions of extension with MetadataXmp or embedding, abstract, data class, etc. I don't seem to be able to introduce @Relation.