diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-15 20:24:58 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-15 20:25:43 -0800 |
commit | ace84a003cb48f60ca478c05c1fd8a57d37663cf (patch) | |
tree | 347c325ef8944acb62956b3d57071e1944b52d9e /activerecord | |
parent | 7bf9cbb7667d3725535c1410df95892891665a95 (diff) | |
download | rails-ace84a003cb48f60ca478c05c1fd8a57d37663cf.tar.gz rails-ace84a003cb48f60ca478c05c1fd8a57d37663cf.tar.bz2 rails-ace84a003cb48f60ca478c05c1fd8a57d37663cf.zip |
support finding by a ruby class [#5979 state:resolved]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 2eda404490..32c7d08daa 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -27,6 +27,9 @@ module ActiveRecord 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 diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 24539df6ff..e39b1f396c 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -438,6 +438,13 @@ class RelationTest < ActiveRecord::TestCase 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]) |