1

I'm currently trying my hand at Jetpack Compose and Firebase with the MVVM architecture. In the process, I came across a question that I can't answer with google.

My project is structured as follows:

TaskModel -> data class
TaskListModel -> data class (contains a collection of tasks)

(TaskListModel -> TaskModel = 1:n)

TaskViewModel -> uses TaskRepository (insert, update, get, ...)

TaskListViewModel -> uses TaskListRepository (insert, update, get, ...)

I have learned that a ViewModel is passed to the respective screen by the navigation, so that the screen gets access to the data.

My question: How do I access the TaskModels?

Option 1: Should I do it via the TaskListViewModel, since a TaskList contains a collection of TaskModels?

Option 2: Should I do it via the TaskViewModel by passing the uuid of the TaskList and get the data based on that?

But no matter which option makes more sense, either the collection in the TaskList becomes superfluous or the TaskViewModel becomes superfluous.

1
  • Thank you for your answer. In the examples, only one model is used (1. Book and 2. Product) and I would need an example with at least two models that are in a relationship like 1:n. Otherwise, the examples are exactly as I have implemented the code so far. Commented Jun 12, 2022 at 9:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.