From 38df43d492816dbbdc34b32aa639e55782f403d4 Mon Sep 17 00:00:00 2001 From: John Devine Date: Sun, 4 May 2008 14:06:28 -0500 Subject: [PATCH] Make sure needed table joins are included :select option --- activerecord/lib/active_record/associations.rb | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 83f83c3..7944d23 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1498,6 +1498,12 @@ module ActiveRecord return [] unless order && order.is_a?(String) 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) @@ -1516,9 +1522,17 @@ module ActiveRecord order_table_name != table_name end end + + def include_eager_select?(options) + selects = selects_tables(options) + return false unless selects.any? + selects.any? do |select| + select != table_name + end + 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) -- 1.5.2.5