Bog'liq Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019
one-to- many relations: The
@Relation
annotation.
@Relation
is a very handy annotation that automatically retrieves records from
related entities. You can apply it to a
List
or
Set
of objects and Room will take care
of the rest for you. To see the
@Relation
in action, create a new class under the
data ▸ model package and name it
QuestionAndAllAnswers .
Replace everything inside with the following:
class
}
Step by step:
1. Since you want to be able to access all the fields in the
Question
entity, we are
using the
@Embedded
annotation to retrieve all the properties from that entity. If
you need a reminder of how annotations like
@Embedded
work, take a look at the