Skip to content
This repository
Browse code

Override respond_to? in ActiveRecord::Relation to go with

method_missing.
  • Loading branch information...
commit 74ed123e082a9b2b160ddecc2eb141f1678c600a 1 parent fefb4c7
Emilio Tagua authored August 18, 2009
8  activerecord/lib/active_record/relation.rb
@@ -73,6 +73,14 @@ def conditions(conditions)
73 73
       end
74 74
     end
75 75
 
  76
+    def respond_to?(method)
  77
+      if @relation.respond_to?(method) || Array.instance_methods.include?(method.to_s)
  78
+        true
  79
+      else
  80
+        super
  81
+      end
  82
+    end
  83
+
76 84
     private
77 85
       def method_missing(method, *args, &block)
78 86
         if @relation.respond_to?(method)
8  activerecord/test/cases/relations_test.rb
@@ -71,5 +71,13 @@ def test_joins_with_string_array
71 71
     ).to_a
72 72
     assert_equal 1, person_with_reader_and_post.size
73 73
   end
  74
+
  75
+  def test_relation_responds_to_delegated_methods
  76
+    relation = Topic.all
  77
+
  78
+    ["map", "uniq", "sort", "insert", "delete", "update"].each do |method|
  79
+      assert relation.respond_to?(method)
  80
+    end
  81
+  end
74 82
 end
75 83
 

0 notes on commit 74ed123

Please sign in to comment.
Something went wrong with that request. Please try again.