3

So for example ...
Lets say I have a Posts model and a News model, that are essentially the same thing (structure wise)
columns are
* title
* content
* createdat
* updatedat

The client has requested showing both news and Posts on the same page interleaved and sorted by created_at date ...
Does anyone know how I would go about doing something like this?

concept47
  • 30,257
  • 12
  • 52
  • 74

2 Answers2

2
(Post.all + News.all).sort_by(&:created_at)
cwninja
  • 9,550
  • 1
  • 29
  • 22
0

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.

Neal
  • 4,468
  • 36
  • 33