I have a Videos model and a News model. I want to paginate these in a feed and interleave them by their created_at date.
I considered creating a Feed model and adding a feed_id to both the Videos and News model but I am unsure of how I would iterate through the attributes. I cannot call feed.title or feed.content because those attributes are located in the News and Video models.
This answer suggests (Video.all + News.all).sort_by(&:created_at) which can be iterated through like this however another user suggests:
Just a warning, cwninja's answer will be really slow with large datasets because it requires pulling ALL of the members out of the database and then running a sort on them.
I would rarely suggest raw SQL, but in this case I can't think of a better way.
I am using a Postgres database.