Hi, I get stuck with Relations in Room. Trying to ...
# room
m
Hi, I get stuck with Relations in Room. Trying to connect channel and members, based on memberships. Let’s say that the structure is:
Copy code
data class Membership(
    @PrimaryKey
    val id: String,
    val channel: String, // channelId
    val member: String, // memberId
)
Copy code
data class Channel(
    @PrimaryKey val id: String,
    val name: String,
    ...
)
Copy code
data class Member(
    @PrimaryKey val id: String,
    override val name: String,
    ...
)
Is it possible to create a
ChannelWithMembers
and
MemberWithChannels
with relations?
Well, the problem here is that parent and entity column must be unique. When I changed it to
channelId
and
memberId
it works like a charm. Is it by design or bug?
y
i'm guessing it doesn't know which id to use when you have two columns w/ the same name. @Column info could've solved it but you can also file a bug with a sample if you want us to take a look. Meanwhile, take a look at the new Map return type support. That could make these a little less verbose (but you still need non-conflicting column names) https://developer.android.com/jetpack/androidx/releases/room