Imagine we have one to many relationship. Two tables, one is parent_table and another is child_table. Two entity classes called ParentEntity and ChildEntity. And one embeded class called ParentWithChild using it on join query result.
ParentEntity Class
@Entity(tableName = "parent_table")
data class ChildEntity(
@ColumnInfo(name = "parent_id")
@PrimaryKey(autoGenerate = false)
val id: String,
@ColumnInfo(name = "parent_name")
val name: String,
)
ChildEntity Class
@Entity(
tableName = "child_table",
foreignKeys = [ForeignKey(
entity = ParentEntity::class,
parentColumns = ["parent_id"],
childColumns = ["parent_owner_id"],
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE,
deferred = false
)])
data class ChildEntity(
@ColumnInfo(name = "child_id")
@PrimaryKey(autoGenerate = false)
val id: String,
@ColumnInfo(name = "parent_owner_id")
val childId: String,
@ColumnInfo(name = "child_name")
val name: String,
)
ParentWithChild Class
data class ParentWithChild(
@Embedded
val parent: ParentEntity?,
@Embedded
val child : ChildEntity?,
)
And the sample query in dao class is
@Query("""
select *
from parent_table left join child_table on parent_table.parent_id = child_table.parent_owner_id
""")
abstract fun loadParentsWithChildren(): Flow<List<ParentWithChild>>
Now two scenarios come to play, if we use loadParentsWithChildren() mehtod.
1- If parent table is updated the trigger happens and the new data stream emitted by room.
2- If the child table is updated the room does not re fetch the join query statements.
My problem is the second scenario, what am I doing wrong ?
- Using Room Stable Release 2.2.6
Thanks in advance.