During development I face situation where I have to save Object with fields and List
Looking for the solution I came across Room @Relation
I've damm UserAndPets example
class ShoppingListAndItems(
@Embedded
var shoppingList: ShoppingListCache = ShoppingListCache.emptyInstance(),
@Relation(
parentColumn = ShoppingListCache.COLUMN_PARENT_ID,
entityColumn = ShoppingItemCache.ENTITY_COLUMN)
var shoppingItems: List<ShoppingItemCache> = emptyList()
)
The problem with that kind solution, using following DAO - list is not being updated:
@Query("""SELECT * FROM ${ShoppingListCache.TABLE_NAME}
WHERE ${ShoppingListCache.COLUMN_IS_ARCHIVED} = :isArchived""")
fun getListOfShoppingList(isArchived: Boolean): List<ShoppingListAndItems>
Moreover that POJO cannot be use more then return type - what is disappointing
@Insert
fun insertShoppingListAndItems(newShoppingListAndItems: ShoppingListAndItems) // Error
@Delete
fun insertShoppingListAndItems(newShoppingListAndItems: ShoppingListAndItems) // Error
Am I doing something wrong or Room doesn't support such functionality?