Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8178

Show
Ignore:
Timestamp:
11/21/07 07:32:44 (9 months ago)
Author:
bitsweat
Message:

Dynamic finders on association collections respect association :limit. Closes #10227 [Jack Danger Canty]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r8172 r8178  
    11*SVN* 
     2 
     3* Dynamic finders on association collections respect association :order and :limit.  #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty] 
    24 
    35* Add 'foxy' support for fixtures of polymorphic associations. #10183 [jbarnette, David Lowenfels] 
  • trunk/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb

    r8174 r8178  
    134134 
    135135        def construct_scope 
    136           { :find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false, :order => @reflection.options[:order] } } 
     136          { :find => {  :conditions => @finder_sql, 
     137                        :joins => @join_sql, 
     138                        :readonly => false, 
     139                        :order => @reflection.options[:order], 
     140                        :limit => @reflection.options[:limit] } } 
    137141        end 
    138142 
  • trunk/activerecord/lib/active_record/associations/has_many_association.rb

    r8174 r8178  
    168168          create_scoping = {} 
    169169          set_belongs_to_association_for(create_scoping) 
    170           { :find => { :conditions => @finder_sql, :readonly => false, :order => @reflection.options[:order] }, :create => create_scoping } 
     170          { :find => { :conditions => @finder_sql, :readonly => false, :order => @reflection.options[:order], :limit => @reflection.options[:limit] }, :create => create_scoping } 
    171171        end 
    172172    end 
  • trunk/activerecord/lib/active_record/associations/has_many_through_association.rb

    r8174 r8178  
    237237                         :joins       => construct_joins, 
    238238                         :select      => construct_select, 
    239                          :order       => @reflection.options[:order] } } 
     239                         :order       => @reflection.options[:order], 
     240                         :limit       => @reflection.options[:limit] } } 
    240241        end 
    241242 
  • trunk/activerecord/test/associations_test.rb

    r8174 r8178  
    484484  end 
    485485 
     486  def test_dynamic_find_all_should_respect_association_limit 
     487    assert_equal 1, companies(:first_firm).limited_clients.find(:all, :conditions => "type = 'Client'").length 
     488    assert_equal 1, companies(:first_firm).limited_clients.find_all_by_type('Client').length 
     489  end 
     490 
     491  def test_dynamic_find_all_limit_should_override_association_limit 
     492    assert_equal 2, companies(:first_firm).limited_clients.find(:all, :conditions => "type = 'Client'", :limit => 9_000).length 
     493    assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length 
     494  end 
     495 
    486496  def test_triple_equality 
    487497    assert !(Array === Firm.find(:first).clients) 
     
    11191129    assert_equal [Comment.find(3), Comment.find(6), Comment.find(7), Comment.find(10)], authors(:david).comments_desc.find(:all, :conditions => "comments.type = 'SpecialComment'", :order => 'comments.id') 
    11201130    assert_equal [Comment.find(3), Comment.find(6), Comment.find(7), Comment.find(10)], authors(:david).comments_desc.find_all_by_type('SpecialComment', :order => 'comments.id') 
     1131  end 
     1132 
     1133  def test_dynamic_find_all_should_respect_association_limit_for_through 
     1134    assert_equal 1, authors(:david).limited_comments.find(:all, :conditions => "comments.type = 'SpecialComment'").length 
     1135    assert_equal 1, authors(:david).limited_comments.find_all_by_type('SpecialComment').length 
     1136  end 
     1137 
     1138  def test_dynamic_find_all_order_should_override_association_limit_for_through 
     1139    assert_equal 4, authors(:david).limited_comments.find(:all, :conditions => "comments.type = 'SpecialComment'", :limit => 9_000).length 
     1140    assert_equal 4, authors(:david).limited_comments.find_all_by_type('SpecialComment', :limit => 9_000).length 
    11211141  end 
    11221142 
     
    18651885  end 
    18661886 
     1887  def test_dynamic_find_all_should_respect_association_limit 
     1888    assert_equal 1, projects(:active_record).limited_developers.find(:all, :conditions => "name = 'Jamis'").length 
     1889    assert_equal 1, projects(:active_record).limited_developers.find_all_by_name('Jamis').length 
     1890  end 
     1891 
     1892  def test_dynamic_find_all_order_should_override_association_limit 
     1893    assert_equal 2, projects(:active_record).limited_developers.find(:all, :conditions => "name = 'Jamis'", :limit => 9_000).length 
     1894    assert_equal 2, projects(:active_record).limited_developers.find_all_by_name('Jamis', :limit => 9_000).length 
     1895  end 
     1896 
    18671897  def test_new_with_values_in_collection 
    18681898    jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis') 
  • trunk/activerecord/test/fixtures/author.rb

    r8174 r8178  
    1717  has_many :comments, :through => :posts 
    1818  has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC' 
     19  has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1 
    1920  has_many :funky_comments, :through => :posts, :source => :comments 
    2021