aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/through_association.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-03-08 23:28:10 -0800
committerJosé Valim <jose.valim@gmail.com>2012-03-08 23:28:10 -0800
commit2b9041ba96375467717a79b0d2c5e6ecca038b5e (patch)
treea618b1a72f5944baeb48b13e0d9314c257c173ed /activerecord/lib/active_record/associations/through_association.rb
parent98144207789893c480ed42b007f4964070d9f870 (diff)
parentf18c0547b0a7ff97fec78cb1f0c95c2531290a94 (diff)
downloadrails-2b9041ba96375467717a79b0d2c5e6ecca038b5e.tar.gz
rails-2b9041ba96375467717a79b0d2c5e6ecca038b5e.tar.bz2
rails-2b9041ba96375467717a79b0d2c5e6ecca038b5e.zip
Merge pull request #5347 from rafaelfranca/fix-has_many_association-3-2
[3-2-stable] Fix has many through associations when mass_assignment_sanitizer is :strict
Diffstat (limited to 'activerecord/lib/active_record/associations/through_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb10
1 files changed, 7 insertions, 3 deletions
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)