Changeset 8178
- Timestamp:
- 11/21/07 07:32:44 (9 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/has_many_association.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations/has_many_through_association.rb (modified) (1 diff)
- trunk/activerecord/test/associations_test.rb (modified) (3 diffs)
- trunk/activerecord/test/fixtures/author.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r8172 r8178 1 1 *SVN* 2 3 * Dynamic finders on association collections respect association :order and :limit. #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty] 2 4 3 5 * 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 134 134 135 135 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] } } 137 141 end 138 142 trunk/activerecord/lib/active_record/associations/has_many_association.rb
r8174 r8178 168 168 create_scoping = {} 169 169 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 } 171 171 end 172 172 end trunk/activerecord/lib/active_record/associations/has_many_through_association.rb
r8174 r8178 237 237 :joins => construct_joins, 238 238 :select => construct_select, 239 :order => @reflection.options[:order] } } 239 :order => @reflection.options[:order], 240 :limit => @reflection.options[:limit] } } 240 241 end 241 242 trunk/activerecord/test/associations_test.rb
r8174 r8178 484 484 end 485 485 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 486 496 def test_triple_equality 487 497 assert !(Array === Firm.find(:first).clients) … … 1119 1129 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') 1120 1130 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 1121 1141 end 1122 1142 … … 1865 1885 end 1866 1886 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 1867 1897 def test_new_with_values_in_collection 1868 1898 jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis') trunk/activerecord/test/fixtures/author.rb
r8174 r8178 17 17 has_many :comments, :through => :posts 18 18 has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC' 19 has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1 19 20 has_many :funky_comments, :through => :posts, :source => :comments 20 21