aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/through_association.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-03-05 17:00:48 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-03-07 21:07:29 -0300
commitc9c7ee7710a637e1dd3c1d4be3960fe22f8ee3d1 (patch)
treea6c0cea59581865d7d8e4b7c2fa07117ccf6e61a /activerecord/lib/active_record/associations/through_association.rb
parente9bf0e3157fcc15f3520559a34bbfdd894dd8112 (diff)
downloadrails-c9c7ee7710a637e1dd3c1d4be3960fe22f8ee3d1.tar.gz
rails-c9c7ee7710a637e1dd3c1d4be3960fe22f8ee3d1.tar.bz2
rails-c9c7ee7710a637e1dd3c1d4be3960fe22f8ee3d1.zip
Not need to pass join attributes to association build
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)