diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-05-15 21:54:46 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-05-15 21:54:46 +0100 |
commit | 879493c35fd8d9e12e5cf3e56cd67ff07c3345c5 (patch) | |
tree | 9615859e1d9a52f71da444b0b7359817bb6acc50 /activerecord/lib/active_record/associations.rb | |
parent | d6ecce66f4e125531875006eea8022b73fe135b5 (diff) | |
parent | fc02eabf296d6edb74a95174c7322293a54c9492 (diff) | |
download | rails-879493c35fd8d9e12e5cf3e56cd67ff07c3345c5.tar.gz rails-879493c35fd8d9e12e5cf3e56cd67ff07c3345c5.tar.bz2 rails-879493c35fd8d9e12e5cf3e56cd67ff07c3345c5.zip |
Merge commit 'mainstream/master'
Conflicts:
actionmailer/lib/action_mailer/base.rb
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index fb5f1f8a8c..c17e35f5e0 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1451,9 +1451,6 @@ module ActiveRecord join_dependency.joins_for_table_name(table) }.flatten.compact.uniq - - - is_distinct = !options[:joins].blank? || include_eager_conditions?(options, tables_from_conditions) || include_eager_order?(options, tables_from_order) sql = "SELECT " if is_distinct @@ -1500,26 +1497,28 @@ module ActiveRecord order.scan(/([\.\w]+).?\./).flatten end + def selects_tables(options) + select = options[:select] + return [] unless select && select.is_a?(String) + select.scan(/"?([\.\w]+)"?.?\./).flatten + end + # Checks if the conditions reference a table other than the current model table - def include_eager_conditions?(options,tables = nil) - tables = conditions_tables(options) - return false unless tables.any? - tables.any? do |condition_table_name| - condition_table_name != table_name - end + def include_eager_conditions?(options, tables = nil) + ((tables || conditions_tables(options)) - [table_name]).any? end # Checks if the query order references a table other than the current model's table. - def include_eager_order?(options,tables = nil) - tables = order_tables(options) - return false unless tables.any? - tables.any? do |order_table_name| - order_table_name != table_name - end + def include_eager_order?(options, tables = nil) + ((tables || order_tables(options)) - [table_name]).any? + end + + def include_eager_select?(options) + (selects_tables(options) - [table_name]).any? end def references_eager_loaded_tables?(options) - include_eager_order?(options) || include_eager_conditions?(options) + include_eager_order?(options) || include_eager_conditions?(options) || include_eager_select?(options) end def using_limitable_reflections?(reflections) |