Take the 2008 Git User's Survey and help out! [ hide ]

public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/josh/rails.git
Search Repo:
Make sure needed table joins are included :select option. [#110 
state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
jdevine (author)
Sun May 04 12:08:19 -0700 2008
lifo (committer)
Thu May 15 05:42:28 -0700 2008
commit  b28b54cab090bed8f099ef375b419a8f92390dd4
tree    e697ac7a8585f48ee92d39f6eaf102e3c63692cf
parent  6df995bbf2f0fcb26b7a1ba8d4e41ed9de77b6c8
...
1500
1501
1502
 
 
 
 
 
 
1503
1504
1505
...
1518
1519
1520
 
 
 
 
 
 
 
 
1521
1522
 
1523
1524
1525
...
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
...
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
 
1536
1537
1538
1539
0
@@ -1500,6 +1500,12 @@ module ActiveRecord
0
           order.scan(/([\.\w]+).?\./).flatten
0
         end
0
 
0
+ def selects_tables(options)
0
+ select = options[:select]
0
+ return [] unless select && select.is_a?(String)
0
+ select.scan(/"?([\.\w]+)"?.?\./).flatten
0
+ end
0
+
0
         # Checks if the conditions reference a table other than the current model table
0
         def include_eager_conditions?(options,tables = nil)
0
           tables = conditions_tables(options)
0
@@ -1518,8 +1524,16 @@ module ActiveRecord
0
           end
0
         end
0
 
0
+ def include_eager_select?(options)
0
+ selects = selects_tables(options)
0
+ return false unless selects.any?
0
+ selects.any? do |select|
0
+ select != table_name
0
+ end
0
+ end
0
+
0
         def references_eager_loaded_tables?(options)
0
- include_eager_order?(options) || include_eager_conditions?(options)
0
+ include_eager_order?(options) || include_eager_conditions?(options) || include_eager_select?(options)
0
         end
0
 
0
         def using_limitable_reflections?(reflections)
...
859
860
861
862
 
863
864
865
 
 
866
867
 
 
 
868
869
870
...
859
860
861
 
862
863
 
 
864
865
866
867
868
869
870
871
872
873
0
@@ -859,12 +859,15 @@ class FinderTest < ActiveRecord::TestCase
0
   end
0
 
0
   def test_find_with_order_on_included_associations_with_construct_finder_sql_for_association_limiting_and_is_distinct
0
- assert_equal 2, Post.find(:all,:include=>{:authors=>:author_address},:order=>' author_addresses.id DESC ', :limit=>2).size
0
+ assert_equal 2, Post.find(:all, :include => { :authors => :author_address }, :order => ' author_addresses.id DESC ', :limit => 2).size
0
 
0
- assert_equal 3, Post.find(:all,:include=>{:author=>:author_address,:authors=>:author_address},
0
- :order=>' author_addresses_authors.id DESC ', :limit=>3).size
0
+ assert_equal 3, Post.find(:all, :include => { :author => :author_address, :authors => :author_address},
0
+ :order => ' author_addresses_authors.id DESC ', :limit => 3).size
0
   end
0
 
0
+ def test_with_limiting_with_custom_select
0
+ assert_equal 3, Post.find(:all, :include => :author, :select => ' posts.*, authors.id as "author_id"', :limit => 3).size
0
+ end
0
 
0
   protected
0
     def bind(statement, *vars)

Comments

    No one has commented yet.