Created
August 31, 2012 15:11
-
-
Save jefferyf/3554311 to your computer and use it in GitHub Desktop.
Conditional where clause generation with squeel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Class method on Intakes model | |
def self.find_for_report(options={}) | |
joins{intake_grant}. | |
where do | |
conditions = {} | |
conditions[pending.eq] = false | |
conditions[intake_grant_id] = options[:grant_id] unless options[:grant_id].blank? | |
conditions[intake_date.gt] = options[:from] unless options[:from].blank? | |
conditions[intake_date.lt] = options[:to] unless options[:to].blank? | |
conditions | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment