Created
January 14, 2010 13:01
-
-
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.
This file contains 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
# 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