Imagine I have two models:
foo and bar.
I have a page where I show X items (paginating with kaminari).
Those items would be a combination of foo and bar.
So I need to retrieve an array of X items ordered by created_at.
Imagine that foo have 25 items and bar just 10.
I ask for 10 items, and I need the first 10 items ordered by created_at. Maybe there are 7 foo and 3 bar mixed in.
I know that I can retrieve and merge them, but the problem is that if I request 10 foo and 10 bar, order by date and get the first 10. If I ask for page two, I will be losing items.
Maybe I’m asking too much, but would be good ask for a page 1, retrieve 10 items of foo/bar mix, ask for page 2, and same stuff. Maybe I need a third table?
Ideas? 🙂
You could create a view that is the combination of the two tables. Then query for the top 10 records in that table. Check out this gem: https://rubygems.org/gems/rails_sql_views.
If these are similar concepts, you could actually use one table and two models with single table inheritance.