I have three classes with the following relationships:
class Feed : RealmObject {
var items: RealmList<FeedItem> = realmListOf()
}
class FeedItem : RealmObject {
val feed: RealmResults<Feed> by backlinks(Feed::items)
}
class FeedMedia: EmbeddedRealmObject {
var item: FeedItem?
}
I persisted them with this:
realm.write {
for (item in feed.items) {
item.feedId = feed.id
val media = item.media
if (media != null) {
media?.item = item
}
}
copyToRealm(feed)
}
Then given a feedMedia object, I want to get the feed,
val item = media.item
val feed = item.feed.first()
The first line above works, but the second to get the feed throws an NoSuchElementException:
failed because it threw an exception/error
java.util.concurrent.ExecutionException: java.util.NoSuchElementException: List is empty.
at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:515)
at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:474)
at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:316)
at androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96)
Any advice on how to resolve this?