Skip to content

Commit

Permalink
@klass also uses DynamicFinderMatch, so no need for it on the relation
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Sep 27, 2010
1 parent b1f5e90 commit 133742d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 0 additions & 9 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,6 @@ def method_missing(method, *args, &block)
scoping { @klass.send(method, *args, &block) }
elsif arel.respond_to?(method)
arel.send(method, *args, &block)
elsif match = DynamicFinderMatch.match(method)
attributes = match.attribute_names
super unless @klass.send(:all_attributes_exists?, attributes)

if match.finder?
find_by_attributes(match, attributes, *args)
elsif match.instantiator?
find_or_instantiator_by_attributes(match, attributes, *args, &block)
end
else
super
end
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/relations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def test_apply_relation_as_where_id
assert_equal 5, Post.where(:id => post_authors).size
end

def test_dynamic_finder
x = Post.where('author_id = ?', 1)
assert x.klass.respond_to?(:find_by_id), '@klass should handle dynamic finders'
end

def test_multivalue_where
posts = Post.where('author_id = ? AND id = ?', 1, 1)
assert_equal 1, posts.to_a.size
Expand Down

0 comments on commit 133742d

Please sign in to comment.