I have to generate a listing of receipts in rails which have to be purchased by item's order relationship area (payment_method_meta_type.name).

Models :


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

I acquired a range 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)

Within the view I'm able to show the payment_method_meta_type.title too

- @receipts.each do |o|
    %td #{o.receipt_number}
    %td #{o.deposit.payment_method_meta_type.name}

But how do i show their email list through the order of receipts.deposit.payment_method_meta_type.name within the controller after i produce the assortment of the receipts array?

Do this:

@receipts = Receipt.all(:joins => {:deposit => :payment_method_meta_type},
              :conditions => {:date => @start_date..@end_date}, 
              :order => "payment_method_meta_types.name ASC", 
              :limit => limit, :offset => offset)

thx , I finally settle your differences, use 'include' within the query string

@receipts = Receipt.find(:all, :include => {:deposit => [:payment_method_meta_type] } ,:conditions => ["Receipts.business_date BETWEEN ? AND ?", @current_month_start_date, @current_month_end_date],:order => "tag_types.name , Receipts.business_date DESC",:limit => limit)