aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/through_association_scope.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-15 17:46:09 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-15 17:46:09 +0100
commitedc176d33be9499f4c096779c5b4711b5daf0c06 (patch)
treec775c7643fca33a3ff18aaa724064e2a167c8616 /activerecord/lib/active_record/associations/through_association_scope.rb
parentd619e399380cd840f9f5ec88bb3d823fbb1f4d08 (diff)
downloadrails-edc176d33be9499f4c096779c5b4711b5daf0c06.tar.gz
rails-edc176d33be9499f4c096779c5b4711b5daf0c06.tar.bz2
rails-edc176d33be9499f4c096779c5b4711b5daf0c06.zip
Make sure nested through associations are read only
Diffstat (limited to 'activerecord/lib/active_record/associations/through_association_scope.rb')
-rw-r--r--activerecord/lib/active_record/associations/through_association_scope.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb
index a52672eecd..51ab8869ed 100644
--- a/activerecord/lib/active_record/associations/through_association_scope.rb
+++ b/activerecord/lib/active_record/associations/through_association_scope.rb
@@ -8,15 +8,18 @@ module ActiveRecord
protected
def construct_scope
- { :create => construct_owner_attributes(@reflection),
- :find => { :conditions => construct_conditions,
- :joins => construct_joins,
- :include => @reflection.options[:include] || @reflection.source_reflection.options[:include],
- :select => construct_select,
- :order => @reflection.options[:order],
- :limit => @reflection.options[:limit],
- :readonly => @reflection.options[:readonly],
- } }
+ scope = {}
+ scope[:find] = {
+ :conditions => construct_conditions,
+ :joins => construct_joins,
+ :include => @reflection.options[:include] || @reflection.source_reflection.options[:include],
+ :select => construct_select,
+ :order => @reflection.options[:order],
+ :limit => @reflection.options[:limit],
+ :readonly => @reflection.options[:readonly]
+ }
+ scope[:create] = construct_owner_attributes(@reflection) unless @reflection.nested?
+ scope
end
# Build SQL conditions from attributes, qualified by table name.
@@ -299,6 +302,12 @@ module ActiveRecord
end
alias_method :sql_conditions, :conditions
+
+ def ensure_not_nested
+ if @reflection.nested?
+ raise HasManyThroughNestedAssociationsAreReadonly.new(@owner, @reflection)
+ end
+ end
end
end
end