Skip to content

Instantly share code, notes, and snippets.

@henrik
Created January 14, 2010 13:01
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 henrik/277141 to your computer and use it in GitHub Desktop.
Save henrik/277141 to your computer and use it in GitHub Desktop.
Monkeypatch version of a patch by John Trupiano to fix a Rails bug with :include and symbol keys on :conditions.
# config/initializers/monkeypatches.rb
# Work around a Rails bug where e.g. :include => :foo, :conditions => { :'foo.bar' => 'baz' }
# would not include 'foo' unless 'foo.bar' is a string.
# https://rails.lighthouseapp.com/projects/8994/tickets/2998-named_scope-ignores-include-option
module ActiveRecord::Associations::ClassMethods
def tables_in_hash(hash)
return [] if hash.blank?
tables = hash.map do |key, value|
if value.is_a?(Hash)
key.to_s
else
tables_in_string(key.to_s) if key.is_a?(String) || key.is_a?(Symbol)
end
end
tables.flatten.compact
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment