Query multiple models/tables for an "Overview" page

Hey guys. I want to create a overview page for my application that contains the latest activity on the site, from a few different sources. Lets say we have messages, comments, files and tasks (much like Basecamp, if you've ever used it) and you want to display them all in one big list, intermixed, and sorted by date.

I know I could run queries on all the separate models and then combine the results, but because this will be paginated, I would end up getting more records than I really need, and having to trash some, that seems wasteful and and potentially a hit to performance. So, I'd really like to be able to put a LIMIT on the DB query itself, as well, if possible.

What do you think is the best way to go about this? Thanks a lot guys!

Seirie wrote:

Hey guys. I want to create a overview page for my application that contains the latest activity on the site, from a few different sources. Lets say we have messages, comments, files and tasks (much like Basecamp, if you've ever used it) and you want to display them all in one big list, intermixed, and sorted by date.

I know I could run queries on all the separate models and then combine the results, but because this will be paginated, I would end up getting more records than I really need, and having to trash some, that seems wasteful and and potentially a hit to performance. So, I'd really like to be able to put a LIMIT on the DB query itself, as well, if possible.

If you're querying multiple tables, then there is no way to do this. If you're going to display a total of (say) 30 records, I think you'll just have to do LIMIT 30 on each table and discard the rest.

You could do some join trickery to get around this, but I suspect that AR wouldn't recognize the results.

What do you think is the best way to go about this? Thanks a lot guys!

Best,

Hmm, alright, I suspected that might be the case. Suppose it's not such a big loss. Thanks Marnen!