jeudi 28 avril 2016

Greendao: How to update to-many entities

My app uses a database with SongVersions having many Tracks. This to-manx relationship is generated by greendao and works fine so far.

But now I try to update a track - let's say to mute it - and the update is only wokring until the next app start. This is, because the udpate is only reflected in the cached list of tracks, but not really persisted to the database.

Here is my code so far (not working)

// iterate through tracks
for (Track track : mSongVersion.getTrackList()) {

  if (trackId.equals(track.getId())) {
   // mute specific track
   track.setMuted(muted);
   mSongVersion.update();
  }
}

SongVersion and Track are the entitiy classes genertated by greendao. SongVersion has an update()-method, but Track has no update()-method. So I was thinking that one has to update a specific track by updating "the whole thing" using SongVersion#update(). But this call only updates the SongVersion, ignoring changes of its tracks...

I also tried some variations of (not) resetting the tracklist to make sure that (no) cached values are interfering, but also to no avail.

Aucun commentaire:

Enregistrer un commentaire