我有 2 个实体:
@Entity(tableName = "author")
data class Author(
@PrimaryKey
@ColumnInfo(name = "id")
val id: String,
@ColumnInfo(name = "name")
val name: String
)
data class Book(
@ColumnInfo(name = "id")
val id: String,
@ColumnInfo(name = "title")
val title: String,
@ColumnInfo(name = "author_id")
var authorId: String
)
我想加入他们的查询:
@Query("SELECT * FROM book JOIN author ON author.id = book.author_id AND author.id = :authorId WHERE book.id = :bookId")
fun item(authorId: String, bookId: String): LiveData<BookWithAuthor>
进入这个实体:
@Entity
data class BookWithAuthor(
@Relation(parentColumn = "author_id", entityColumn = "id")
val author: Author,
@Embedded
val book: Book
)
但是,当我这样做时,我会返回一个 BookWithAuthor 对象,其中 author.id 和 book.id 是相同的 id,在这种情况下它们都是作者的 id。如何消除“join”对象中实体中的“id”属性冲突?