I am trying to implement searching of places by name in android. I have created two entities, Word
and Place
.
@Parcelize
@Entity
data class Place(
@PrimaryKey
val id: String,
val name: String,
val icon: String,
val latitude: Double,
val longitude: Double,
val address: String
) : Parcelable
@Entity
data class Word(
@PrimaryKey(autoGenerate = true)
val id: Int = 0,
val searchWord: String,
val placeId: String
)
I have also created another data class
to model a one-to-many relationship between Word
and Place
.
data class WordWithPlaces(
@Embedded
val word: Word,
@Relation(parentColumn = "placeId", entityColumn = "id")
val places: List<Place>
)
The problem I am getting is that when I query the data I get null
.
This is the query function in the dao
.
@Transaction
@Query("SELECT * FROM Word WHERE searchWord = :searchWord")
fun getWordsWithPlaces(searchWord: String): LiveData<WordWithPlaces>
I need help getting the implementation to work.