Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Override respond_to? in ActiveRecord::Relation to go with

method_missing.
  • Loading branch information...
commit 74ed123e082a9b2b160ddecc2eb141f1678c600a 1 parent fefb4c7
@miloops miloops authored
View
8 activerecord/lib/active_record/relation.rb
@@ -73,6 +73,14 @@ def conditions(conditions)
end
end
+ def respond_to?(method)
+ if @relation.respond_to?(method) || Array.instance_methods.include?(method.to_s)
+ true
+ else
+ super
+ end
+ end
+
private
def method_missing(method, *args, &block)
if @relation.respond_to?(method)
View
8 activerecord/test/cases/relations_test.rb
@@ -71,5 +71,13 @@ def test_joins_with_string_array
).to_a
assert_equal 1, person_with_reader_and_post.size
end
+
+ def test_relation_responds_to_delegated_methods
+ relation = Topic.all
+
+ ["map", "uniq", "sort", "insert", "delete", "update"].each do |method|
+ assert relation.respond_to?(method)
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.