diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-07-14 18:32:24 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-07-14 18:32:28 +0100 |
commit | d5921cdb7a00b393d0ba5f2f795da60a33b11cf1 (patch) | |
tree | 25740721ce3f5280f6b8b6ae1e50011060a82011 /activerecord/lib | |
parent | 4a06489525809755bcb8fd4c05394dbfb900f237 (diff) | |
download | rails-d5921cdb7a00b393d0ba5f2f795da60a33b11cf1.tar.gz rails-d5921cdb7a00b393d0ba5f2f795da60a33b11cf1.tar.bz2 rails-d5921cdb7a00b393d0ba5f2f795da60a33b11cf1.zip |
Remove unintentional API changes. [#1108]
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 13 | ||||
-rw-r--r-- | activerecord/lib/active_record/dynamic_finder_match.rb | 4 |
2 files changed, 8 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 1c3a6b56f3..f4e34657a5 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -418,15 +418,10 @@ module ActiveRecord end def method_missing(method, *args) - case method.to_s - when 'find_or_create' - return find(:first, :conditions => args.first) || create(args.first) - when /^find_or_create_by_(.*)$/ - rest = $1 - return send("find_by_#{rest}", *args) || - method_missing("create_by_#{rest}", *args) - when /^create_by_(.*)$/ - return create Hash[$1.split('_and_').zip(args)] + match = DynamicFinderMatch.match(method) + if match && match.creator? + attributes = match.attribute_names + return send(:"find_by_#{attributes.join('and')}", *args) || create(Hash[attributes.zip(args)]) end if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) diff --git a/activerecord/lib/active_record/dynamic_finder_match.rb b/activerecord/lib/active_record/dynamic_finder_match.rb index b39b291352..dfb8a3ba60 100644 --- a/activerecord/lib/active_record/dynamic_finder_match.rb +++ b/activerecord/lib/active_record/dynamic_finder_match.rb @@ -42,6 +42,10 @@ module ActiveRecord @finder == :first && !@instantiator.nil? end + def creator? + @finder == :first && @instantiator == :create + end + def bang? @bang end |