Skip to content

Instantly share code, notes, and snippets.

@LRDesign
Created March 24, 2010 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LRDesign/342778 to your computer and use it in GitHub Desktop.
Save LRDesign/342778 to your computer and use it in GitHub Desktop.
class Cart < ActiveRecord::Base
belongs_to :person
has_many :event_registrations, :dependent => :destroy
has_many :membership_applications, :dependent => :destroy
has_one :payment, :dependent => :destroy
end
class Payment < ActiveRecord::Base
belongs_to :cart
end
class Admin::PaymentsController < Admin::AdminController
def index
if params[:date]
@show_only = DateTime.new(params[:date]['show_only(1i)'].to_i, params[:date]['show_only(2i)'].to_i)
conditions = { :paid_at => (@show_only.beginning_of_month..@show_only.end_of_month) }
joins = :cart
order = 'paid_at ASC'
@payments = Payment.find(:all, :conditions => conditions, :order => order, :include => joins).paginate
else
@payments = Payment.paginate :order => 'paid_at DESC', :page => params[:page]
end
end
def show
end
end
# doesn't include any joins from the :include => eager load call!
Payment Load (0.3ms) SELECT * FROM `payments` WHERE (`payments`.`paid_at` BETWEEN '2010-03-01 00:00:00' AND '2010-03-31 23:59:59') ORDER BY paid_at ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment