【发布时间】:2020-10-05 13:40:38
【问题描述】:
@Entity
data class User(
@PrimaryKey val userId: Long,
val name: String,
val age: Int
)
@Entity
data class Playlist(
@PrimaryKey val playlistId: Long,
val userCreatorId: Long,
val playlistName: String
)
ata class UserWithPlaylists(
@Embedded val user: User,
@Relation(
parentColumn = "userId",
entityColumn = "userCreatorId"
)
val playlists: List<Playlist>
)
@Transaction
@Query("SELECT * FROM User")
fun getUsersWithPlaylists(): List<UserWithPlaylists>
这个例子多一来自https://developer.android.com/training/data-storage/room/relationships ,我的问题
如果我只想获取年龄 =10 的用户
@Query("SELECT * FROM User where age=10")
fun getUsersWithPlaylists(): List<UserWithPlaylists>
但如果我想要 playlistName ="quran"
@Query("SELECT * FROM User where playlistName=quran")
fun getUsersWithPlaylists(): List<UserWithPlaylists>
我不能这样做,因为 roomdb 没有查看播放列表表
【问题讨论】:
-
也许
user.playlistName = quran -
@Andrew 不是这样
-
在您的第二个查询中,您正在询问具有播放列表名称的用户。无论如何,这将如何运作?如果您是新编码员,则需要了解查询数据库的基础知识。你能解释一下你想要达到的目标吗?所以我可以帮你。