aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAnthony Crumley <anthony.crumley@gmail.com>2009-05-04 09:49:43 -0500
committerMichael Koziarski <michael@koziarski.com>2009-05-10 13:36:51 +1200
commit026b78f9076216990bddb1aa5d83d23a647c02a5 (patch)
tree70cdf5bc99af0613d64effc892b0969d461aba43 /activerecord/lib
parent9e0cfdb7f951c0446cdfd3b2cc26443712fe657a (diff)
downloadrails-026b78f9076216990bddb1aa5d83d23a647c02a5.tar.gz
rails-026b78f9076216990bddb1aa5d83d23a647c02a5.tar.bz2
rails-026b78f9076216990bddb1aa5d83d23a647c02a5.zip
Fixed eager load error on find with include => [:table_name] and hash conditions like {:table_name => {:column => 'value'}}
Signed-off-by: Michael Koziarski <michael@koziarski.com>
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 2928b0bf83..781a0290e8 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1671,17 +1671,29 @@ module ActiveRecord
string.scan(/([\.a-zA-Z_]+).?\./).flatten
end
+ 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) if key.is_a?(String)
+ end
+ end
+ tables.flatten.compact
+ end
+
def conditions_tables(options)
# look in both sets of conditions
conditions = [scope(:find, :conditions), options[:conditions]].inject([]) do |all, cond|
case cond
when nil then all
- when Array then all << cond.first
- when Hash then all << cond.keys
- else all << cond
+ when Array then all << tables_in_string(cond.first)
+ when Hash then all << tables_in_hash(cond)
+ else all << tables_in_string(cond)
end
end
- tables_in_string(conditions.join(' '))
+ conditions.flatten
end
def order_tables(options)