Hi , I need to generate a list of receipts in rails which need to be ordered by item's order relationship field (payment_method_meta_type.name
).
Models :
Receipt
Deposit
PaymentMethodMetaType
In Deposit Model:
class Deposit < ActiveRecord::Base
belongs_to :payment_method_meta_type
has_many :receipts, :class_name=>"Receipt", :foreign_key=>"deposit_id",
:dependent => :destroy
end
I got an Array of Receipts in controller already :
@receipts = Receipt.find(:all, :conditions => ["date BETWEEN ? AND ?",
@start_date, @end_date], :order => "date DESC, id DESC",
:limit => limit, :offset => offset)
In the view I can show the payment_method_meta_type.name as well
- @receipts.each do |o|
%tr.
.....
%td #{o.receipt_number}
%td #{o.deposit.payment_method_meta_type.name}
.....
But how can I show the list by the order of receipts.deposit.payment_method_meta_type.name
in the controller when I create the collection of the receipts array?
Cheers~