aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-05-05 11:13:05 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-05-05 11:13:05 -0700
commitf098c80947dee1b420cea4ca647d1ceb3e59eaea (patch)
tree7d58db31397c2c1ef56deea82610b643a1623680 /activerecord/lib/active_record/associations
parentee898e5248d3876372c8303f500afe2baf6f298c (diff)
parent86ea94e4d0c228c79b3709f0c667ba90b02e41cd (diff)
downloadrails-f098c80947dee1b420cea4ca647d1ceb3e59eaea.tar.gz
rails-f098c80947dee1b420cea4ca647d1ceb3e59eaea.tar.bz2
rails-f098c80947dee1b420cea4ca647d1ceb3e59eaea.zip
Merge pull request #358 from baroquebobcat/fix_find_or_create_master
Fix for lighthouse #6741
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 388173c1fb..adfc71d435 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -64,9 +64,12 @@ module ActiveRecord
def method_missing(method, *args, &block)
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)])
+ if match && match.instantiator?
+ record = send(:find_or_instantiator_by_attributes, match, match.attribute_names, *args) do |r|
+ @association.send :set_owner_attributes, r
+ @association.send :add_to_target, r
+ yield(r) if block_given?
+ end
end
if target.respond_to?(method) || (!@association.klass.respond_to?(method) && Class.respond_to?(method))