Skip to content

Instantly share code, notes, and snippets.

@workmad3
Forked from brian-mann/gist:3194911
Created July 28, 2012 22:22
Show Gist options
  • Save workmad3/3195011 to your computer and use it in GitHub Desktop.
Save workmad3/3195011 to your computer and use it in GitHub Desktop.
Dynamically call model methods to chain includes
## Customer.rb
def self.references
includes(:account)
end
def self.forms
includes(:forms)
end
def self.conditionally_include
hash = { :references => true, :locations => false, :forms => false }
hash.inject(self) do |query, (k, v)|
v ? query.send(k) : query
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment