Combining find results from multiple tables/models

Hi all,

I'm wondering if it's possible to merge/combine find results from multiple tables. I have a customers model and customers have invoices and payments. I need to combine the results from the invoice and payment tables to create a customer ledger, which looks like:

@entries = (@customer.payments + @customer.invoices).sort{|a,b| <=>}

When iterating through @entries in the view, you'll can just use 'entry.type' for the second column, if that's literally all you need. It might be nicer, though, to have a different partial for each type, and render each accordingly:

<% @entries.each do |entry| %>   <%= render :partial => (@result.type == Payment ? "payment" : "invoice"), :locals => {:entry => entry} %> <% end %>

Alternatively, it might be sufficient to simply change the style for each line depending on type.

Max Williams wrote:

@entries = (@customer.payments + @customer.invoices).sort{|a,b| <=>}

Oh and by the way, if you need to split this across several pages, you can just call .paginate on the results with a page number, ie

@entries = (@customer.payments + @customer.invoices).sort{|a,b| <=>}.paginate(:page => params[:page], :per_page => 20)

Wow, that's easy... Kinda figured that rails would make this simple... Thanks very much!