aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-27 02:56:11 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-27 02:56:11 +0000
commit02311a5db1800a4654f80ec71e8b7d32b444ff27 (patch)
tree15d81c033d1f947139ec2cb41af0f22d532f5dc5
parent08d23d5375fef67cb3203dfb5e92f41ae87195ee (diff)
downloadrails-02311a5db1800a4654f80ec71e8b7d32b444ff27.tar.gz
rails-02311a5db1800a4654f80ec71e8b7d32b444ff27.tar.bz2
rails-02311a5db1800a4654f80ec71e8b7d32b444ff27.zip
Array attribute conditions work with proxied association collections. Closes #8318.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7133 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/finder_test.rb6
3 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 7373c62082..886a6445da 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Array attribute conditions work with proxied association collections. #8318 [kamal, theamazingrando]
+
* Fix polymorphic has_one associations declared in an abstract class. #8638 [lifofifo, daxhuiberts]
* Fixed validates_associated should not stop on the first error #4276 [mrj/manfred/josh]
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 9d2e186672..77b22aad6a 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -1287,7 +1287,7 @@ module ActiveRecord #:nodoc:
def attribute_condition(argument)
case argument
when nil then "IS ?"
- when Array then "IN (?)"
+ when Array, ActiveRecord::Associations::AssociationCollection then "IN (?)"
when Range then "BETWEEN ? AND ?"
else "= ?"
end
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index f4ab465bf4..c32ceaa466 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -8,7 +8,7 @@ require 'fixtures/developer'
require 'fixtures/post'
class FinderTest < Test::Unit::TestCase
- fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts
+ fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors
def test_find
assert_equal(topics(:first).title, Topic.find(1).title)
@@ -159,6 +159,10 @@ class FinderTest < Test::Unit::TestCase
assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :approved => true }) }
end
+ def test_find_on_association_proxy_conditions
+ assert_equal [1, 2, 3, 5, 6, 7, 8, 9, 10], Comment.find_all_by_post_id(authors(:david).posts).map(&:id).sort
+ end
+
def test_find_on_hash_conditions_with_range
assert_equal [1,2], Topic.find(:all, :conditions => { :id => 1..2 }).map(&:id).sort
assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :id => 2..3 }) }