I'm using objectbox in my project, i have Playlist
entity that include List of Videos
, i'm using ToMany
class for the List<Video> videos
in the Playlist
entity, it's looks the video is saved successfully but when I pull it back from the objectbox, it's doesn't appear.
As you can see in line 154 the video is saved, and in line 156 can't get it back
Here's my code:
late ObjectBox objectBox;
class ObjectBox {
late Box<Video> videoBox;
late Box<Playlist> playlistsBox;
ObjectBox._create(Store store) {
this.videoBox = store.box<Video>();
this.playlistsBox = store.box<Playlist>();
}
static Future<ObjectBox> create() async {
Directory doc = await getApplicationDocumentsDirectory();
final store = await openStore(directory: p.join(doc.path, "videos"));
return ObjectBox._create(store);
}
void createPlaylist(String title, Video video) async {
Playlist playlist = Playlist(title);
video.playlist.target = playlist;
playlist.videos.add(video);
await playlistsBox.put(playlist);
List<Playlist> list = await playlistsBox.getAll().toList();
print(list);
}
}
Playlist entity:
@Entity()
class Playlist {
@Id()
int id = 0;
@Index()
final String title;
@Backlink()
final List<Video> videos = ToMany<Video>();
Playlist(this.title);
}
Video entity:
@Entity()
class Video {
@Id()
int id = 0;
@Index()
final String videoId;
final String title;
final playlist = ToOne<Playlist>();
Video(this.videoId, this.title);
}