Changeset 3240
- Timestamp:
- 12/08/05 04:44:54 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (1 diff)
- trunk/activerecord/test/associations_go_eager_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r3235 r3240 1 1 *SVN* 2 3 * Fixed that using :include together with :conditions array in Base.find would cause NoMethodError #2887 [Paul Hammmond] 2 4 3 5 * PostgreSQL: more robust sequence name discovery. #3087 [Rick Olson] trunk/activerecord/lib/active_record/associations.rb
r3213 r3240 1030 1030 1031 1031 def include_eager_conditions?(options) 1032 return false unless options[:conditions] 1033 1034 options[:conditions].scan(/ ([^.]+)\.[^.]+ /).flatten.any? do |condition_table_name| 1032 conditions = options[:conditions] 1033 return false unless conditions 1034 conditions = conditions.first if conditions.is_a?(Array) 1035 conditions.scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name| 1035 1036 condition_table_name != table_name 1036 1037 end trunk/activerecord/test/associations_go_eager_test.rb
r3051 r3240 84 84 end 85 85 86 def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array 87 comments = Comment.find(:all, :include => :post, :conditions => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id') 88 assert_equal 3, comments.length 89 assert_equal [6,7,8], comments.collect { |c| c.id } 90 end 91 86 92 def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations 87 93 posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1) … … 100 106 assert_equal 2, posts.size 101 107 assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size } 108 end 109 110 def test_eager_with_has_many_and_limit_and_conditions 111 posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.body = 'hello'", :order => "posts.id") 112 assert_equal 2, posts.size 113 assert_equal [4,5], posts.collect { |p| p.id } 114 end 115 116 def test_eager_with_has_many_and_limit_and_conditions_array 117 posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id") 118 assert_equal 2, posts.size 119 assert_equal [4,5], posts.collect { |p| p.id } 120 end 121 122 def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers 123 assert_raises(ArgumentError) do 124 posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ]) 125 end 102 126 end 103 127