diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-04 19:39:50 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-11-04 19:39:50 +0000 |
commit | a5a82d978bd4a46ce73462a0adcb031aa5919ce4 (patch) | |
tree | 4ca0d93e5516f33053af1fdca568607921c34842 /activerecord/lib/active_record/associations/has_many_association.rb | |
parent | 4506a463e4af0c7b8fb7fddea1c666520d895271 (diff) | |
download | rails-a5a82d978bd4a46ce73462a0adcb031aa5919ce4.tar.gz rails-a5a82d978bd4a46ce73462a0adcb031aa5919ce4.tar.bz2 rails-a5a82d978bd4a46ce73462a0adcb031aa5919ce4.zip |
Added extension capabilities to has_many and has_and_belongs_to_many proxies [DHH] Added find_or_create_by_X as a second type of dynamic finder that'll create the record if it doesn't already exist [DHH] Added constrain scoping for creates using a hash of attributes bound to the :creation key [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2872 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_association.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb index f5f27dc410..b04cb81a5c 100644 --- a/activerecord/lib/active_record/associations/has_many_association.rb +++ b/activerecord/lib/active_record/associations/has_many_association.rb @@ -85,6 +85,20 @@ module ActiveRecord end protected + def method_missing(method, *args, &block) + if @target.respond_to?(method) || (!@association_class.respond_to?(method) && Class.respond_to?(method)) + super + else + @association_class.constrain( + :conditions => @finder_sql, + :joins => @join_sql, + :readonly => false, + :creation => { @association_class_primary_key_name => @owner.id }) do + @association_class.send(method, *args, &block) + end + end + end + def find_target find_all end |