diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-27 08:19:12 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-06-27 08:19:12 +0000 |
commit | b5b16a80a9e0386781b370cf110fdc26e13dbc61 (patch) | |
tree | 13d82a1de2c4c2b51368736ae9c0cece18a53747 /activerecord/lib/active_record | |
parent | 02311a5db1800a4654f80ec71e8b7d32b444ff27 (diff) | |
download | rails-b5b16a80a9e0386781b370cf110fdc26e13dbc61.tar.gz rails-b5b16a80a9e0386781b370cf110fdc26e13dbc61.tar.bz2 rails-b5b16a80a9e0386781b370cf110fdc26e13dbc61.zip |
Define collection singular ids method for has_many :through associations. Closes #8763.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7137 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index dd7464432a..ca739eb5dc 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -674,6 +674,7 @@ module ActiveRecord if options[:through] collection_reader_method(reflection, HasManyThroughAssociation) + collection_accessor_methods(reflection, HasManyThroughAssociation, false) else add_multiple_associated_save_callbacks(reflection.name) add_association_callbacks(reflection.name, reflection.options) @@ -1060,7 +1061,7 @@ module ActiveRecord end end - def collection_accessor_methods(reflection, association_proxy_class) + def collection_accessor_methods(reflection, association_proxy_class, writer = true) collection_reader_method(reflection, association_proxy_class) define_method("#{reflection.name}=") do |new_value| @@ -1077,7 +1078,7 @@ module ActiveRecord define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value| ids = (new_value || []).reject { |nid| nid.blank? } send("#{reflection.name}=", reflection.class_name.constantize.find(ids)) - end + end if writer end def add_multiple_associated_save_callbacks(association_name) |