Skip to content

Instantly share code, notes, and snippets.

@sr3d
Created May 30, 2010 00:00
Show Gist options
  • Save sr3d/418648 to your computer and use it in GitHub Desktop.
Save sr3d/418648 to your computer and use it in GitHub Desktop.
class Budget < ActiveRecord::Base
belongs_to :event
belongs_to :category
scope :for_event, lambda {|event_id| where("event_id = ?", event_id ) },
:select => '*, ( SELECT SUM(amount) FROM expenses WHERE event_id = budgets.event_id GROUP BY category_id ) AS total'
# the above code error out, wrong params, 3 for 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment