Skip to content

Instantly share code, notes, and snippets.

@spastorino
Created October 13, 2010 17:26
Show Gist options
  • Save spastorino/624482 to your computer and use it in GitHub Desktop.
Save spastorino/624482 to your computer and use it in GitHub Desktop.
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 78b3507..9fb64b5 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -961,9 +961,12 @@ module ActiveRecord #:nodoc:
attribute_names = match.attribute_names
super unless all_attributes_exists?(attribute_names)
if match.finder?
- options = arguments.extract_options!
- relation = options.any? ? construct_finder_arel(options, current_scoped_methods) : scoped
- relation.send :find_by_attributes, match, attribute_names, *arguments
+ self.class.send :define_method, method_id do |*args|
+ options = args.extract_options!
+ relation = options.any? ? construct_finder_arel(options, current_scoped_methods) : scoped
+ relation.send :find_by_attributes, match, attribute_names, *args
+ end
+ send(method_id, *arguments)
elsif match.instantiator?
scoped.send :find_or_instantiator_by_attributes, match, attribute_names, *arguments, &block
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment