Jacob Ferrero Jacob Ferrero - 3 months ago 9
Android Question

Realm - How to build a feed with multiple types of objects?

I'm trying to use Realm to build a feed for my app. I want the feed to include everything new: posts, comments, events, and other things I have in my app.

I have these all defined as POJOs that extend

RealmObject
, and they all have a
createdAt
property, however I can't find a way to query the whole Realm for objects sorted by their
createdAt
. Is there any way to do that?

Answer

Unfortunately realm does not support polymophism/inheritance in realm objects. You can easily loop through each data set and merge them together according to createdAt. Using DynamicRealm this can be easily done.