title: Is it necessary to always create a viewmodel to perform a simple query or can I access the database from my repository?
body: <p>I am working with a student roll call application, I am using the Room database: Dao, Repository, ViewModel, I have the following tables: Group, Student, StudentGroup, AttendanceRecord, AttendanceStatus, etc.</p>
  <p>Assuming I'm going to take attendance today in group A.
  So I have an activity to take attendance, in this case I need to work with several database tables: StudentGroup to see the students linked to this group, AttendanceRecord to create the attendance record for today's date, AttendanceStatus to save the status of attendance of each student on today's date (attended, absent, requested permission, etc.), Group to display the name of the group in which attendance is being taken.</p>
  <p>From the group table the only data I need is the name to display it on the screen, (the group id comes from getIntent().getExtras()), in this case I need GroupViewModel to get the name String or can I just use my repository?</p>
  <p><strong>GroupRepo</strong></p>
  <pre><code>public String getName(long idGroup){
      Callable&lt;String&gt; callable = () -&gt; groupDao.getName(idGroup);
      String name = null;
  
      ExecutorService executorService = Executors.newSingleThreadExecutor();
      Future&lt;String&gt; future = executorService.submit(callable);
      try {
          name = future.get();
      } catch (InterruptedException e1) {
          e1.printStackTrace();
      } catch (ExecutionException e) {
          e.printStackTrace();
      }
      return name;
  }
  </code></pre>
  <p><strong>Group ViewModel</strong></p>
  <pre><code>private GrupoRepo groupRepo;
  private LiveData&lt;List&lt;Group&gt;&gt; groupList;
  private MutableLiveData&lt;Integer&gt; enableDisable = new MutableLiveData&lt;Integer&gt;();
  
  public GrupoViewModel(@NonNull Application application) {
      super(application);
      groupRepo = new GroupRepo(application);
      enableDisable.setValue(MySettings.getMainView(application.getApplicationContext()));
      groupList = Transformations.switchMap(enableDisable,
              filter -&gt; groupRepo.getFilteredGroups(filter));
  }
  
  public void setFilter(Integer enableDisable) {
      this.enableDisable.setValue(enableDisable);
  }
  
  public LiveData&lt;List&lt;Group&gt;&gt; getGroupList(){
      return groupList;
  }
  
  public String getName(long idGroup){
      return groupRepo.getName(idGroup);
  }
  </code></pre>
  <p>If I only need the name of the group, I think it is much simpler and more useful to obtain it directly from the repository, if I create an instance of GroupViewModel, a list of groups that I do not need in this activity will be initialized. Is that correct or have I misunderstood?</p>
  <p>Which tables do I need to instantiate your ViewModel in my list pass activity considering the uses I mentioned above?</p>