Hello ! I'm wondering how Room manages
null
parameters.
I have a
Category
data class:
data class Category(val name: String?) {
@PrimaryKey(autoGenerate = true)
var id: Long = 0
}
The
name
field is nullable.
This class is used in a one-to-many relationship with an item class, where name is a
foreign key.
I wanted to have a function to get items by category:
@Query("select * from items where category_name = :category")
suspend fun getItemsByCategory(category: String?): List<Item>?
The goal was that if the
category
parameter is null, I would return all
items
where the
category_name
foreign key is null.
Is that possible? Is there a better way to do that? For example, is it possible to prepopulate a db?