0
votes

So I have a simple example like this:

data class PostData(
  val postId: Long,
  val content: String,
  val group: GroupData //A group data where this post belongs to
)

data class GroupData(
  val groupId: Long,
  val name: String,
  val admins: List<Admin>
)

data class Admin(
    val userId: Long,
    val name: String,
    val avatar: String
)

and the Room structure should be like this:

@Entity(tableName = "PostDataLocal")
data class PostDataLocal(
    @PrimaryKey val postId: Long,
    val content: String,
)

@Entity(tableName = "GroupDataLocal")
data class GroupDataLocal(
    val postId: Long,
    @PrimaryKey val groupId: Long,
    val name: String,
)

@Entity(tableName = "AdminDataLocal")
data class AdminDataLocal(
    val groupId: Long,
    @PrimaryKey val userId: Long,
    val name: String,
    val avatar: String,
)

And for the relationship between them:

data class GroupAndItsAdminRelations(
    @Embedded val group: GroupDataLocal,
    @Relation(
        parentColumn = "groupId",
        entityColumn = "groupId"
    )
    val admins: List<AdminDataLocal>
)

data class NeededPostsOfAGroup(
    @Embedded val postData: PostDataLocal,

    @Relation(
        parentColumn = "postId",
        entityColumn = "postId"
    )
    val group: GroupAndItsAdminRelations
)

But to be honest, I don't know if I wrote NeededPostsOfAGroup correctly. Please correct me on these mistake.

My question is, instead of getting all the PostDataLocal in DAO file like this on some tutorials:

@Transaction
@Query("SELECT * FROM PostDataLocal")
fun getAllNeededPostsOfAGroup(): List<NeededPostsOfAGroup>

I would love to get only Post of a specific group (which is the nested GroupAndItsAdminRelations.group.groupId), like "WHERE groupId = :groupId". How do I make that query?

Thank you for your time.