Permalink
Browse files

support finding by a ruby class [#5979 state:resolved]

  • Loading branch information...
1 parent ed91716 commit c7dd1e4df4faedb20a31ec616d0e4360fa53033d @tenderlove tenderlove committed Nov 16, 2010
View
@@ -1,3 +1,7 @@
+*Rails 3.0.3 (November 15, 2010)*
+
+* Support find by class like this: Post.where(:name => Post)
+
*Rails 3.0.2 (November 15, 2010)*
* Dramatic speed increase (see: http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/) [Aaron Patterson]
@@ -32,6 +32,9 @@ def build_from_hash(attributes, default_table)
attribute.in(value)
when ActiveRecord::Base
attribute.eq(value.quoted_id)
+ when Class
+ # FIXME: I think we need to deprecate this behavior
+ attribute.eq(value.name)
else
attribute.eq(value)
end
@@ -433,6 +433,13 @@ def test_find_with_list_of_ar
assert_equal author, authors.first
end
+ class Mary < Author; end
+
+ def test_find_by_classname
+ Author.create!(:name => Mary.name)
+ assert_equal 1, Author.where(:name => Mary).size
+ end
+
def test_find_by_id_with_list_of_ar
author = Author.first
authors = Author.find_by_id([author])

0 comments on commit c7dd1e4

Please sign in to comment.