aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorGabe da Silveira <gabe@websaviour.com>2009-11-17 09:36:23 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2009-11-17 22:25:40 -0800
commitea290e77e6c50b13a0c9000eceaa5412de6918bc (patch)
treec23082de62d9e48b11ce23ad3ce01e674f9d8295 /activerecord/lib
parentfb61fbd35229154f4ced124568697878822336cb (diff)
downloadrails-ea290e77e6c50b13a0c9000eceaa5412de6918bc.tar.gz
rails-ea290e77e6c50b13a0c9000eceaa5412de6918bc.tar.bz2
rails-ea290e77e6c50b13a0c9000eceaa5412de6918bc.zip
Insert generated association members in the same order they are specified when assigning to a has_many :through using the generated *_ids method
[#3491 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 6c5e25010f..fc6f15206a 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/module/delegation'
+require 'active_support/core_ext/enumerable'
module ActiveRecord
class InverseOfAssociationNotFoundError < ActiveRecordError #:nodoc:
@@ -1396,8 +1397,8 @@ module ActiveRecord
end
define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
- ids = (new_value || []).reject { |nid| nid.blank? }
- send("#{reflection.name}=", reflection.klass.find(ids))
+ ids = (new_value || []).reject { |nid| nid.blank? }.map(&:to_i)
+ send("#{reflection.name}=", reflection.klass.find(ids).index_by(&:id).values_at(*ids))
end
end
end