diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-03-05 17:00:48 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-03-08 23:29:28 -0300 |
commit | f18c0547b0a7ff97fec78cb1f0c95c2531290a94 (patch) | |
tree | dee09e91e5b65b3c0e921005b9027e0d1543ea18 /activerecord/lib/active_record/associations | |
parent | 7cd4063162e47e28715cafc021241f14cf8a278d (diff) | |
download | rails-f18c0547b0a7ff97fec78cb1f0c95c2531290a94.tar.gz rails-f18c0547b0a7ff97fec78cb1f0c95c2531290a94.tar.bz2 rails-f18c0547b0a7ff97fec78cb1f0c95c2531290a94.zip |
Not need to pass join attributes to association build
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/through_association.rb | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 9657cb081d..53d49fef2e 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -73,7 +73,9 @@ module ActiveRecord # association def build_through_record(record) @through_records[record.object_id] ||= begin - through_record = through_association.build(construct_join_attributes(record)) + ensure_mutable + + through_record = through_association.build through_record.send("#{source_reflection.name}=", record) through_record end diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb index f95e5337c2..fd0e90aaf0 100644 --- a/activerecord/lib/active_record/associations/through_association.rb +++ b/activerecord/lib/active_record/associations/through_association.rb @@ -37,9 +37,7 @@ module ActiveRecord # situation it is more natural for the user to just create or modify their join records # directly as required. def construct_join_attributes(*records) - if source_reflection.macro != :belongs_to - raise HasManyThroughCantAssociateThroughHasOneOrManyReflection.new(owner, reflection) - end + ensure_mutable join_attributes = { source_reflection.foreign_key => @@ -73,6 +71,12 @@ module ActiveRecord !owner[through_reflection.foreign_key].nil? end + def ensure_mutable + if source_reflection.macro != :belongs_to + raise HasManyThroughCantAssociateThroughHasOneOrManyReflection.new(owner, reflection) + end + end + def ensure_not_nested if reflection.nested? raise HasManyThroughNestedAssociationsAreReadonly.new(owner, reflection) |