0
@@ -692,6 +692,7 @@ module ActiveRecord
0
# * <tt>:uniq</tt> - If true, duplicates will be omitted from the collection. Useful in conjunction with <tt>:through</tt>.
0
# * <tt>:readonly</tt> - If true, all the associated objects are readonly through the association.
0
# * <tt>:validate</tt> - If false, don't validate the associated objects when saving the parent object. true by default.
0
+ # * <tt>:accessible</tt> - Mass assignment is allowed for this assocation (similar to <tt>ActiveRecord::Base#attr_accessible</tt>).
0
# has_many :comments, :order => "posted_on"
0
@@ -774,6 +775,7 @@ module ActiveRecord
0
# association is a polymorphic +belongs_to+.
0
# * <tt>:readonly</tt> - If true, the associated object is readonly through the association.
0
# * <tt>:validate</tt> - If false, don't validate the associated object when saving the parent object. +false+ by default.
0
+ # * <tt>:accessible</tt> - Mass assignment is allowed for this assocation (similar to <tt>ActiveRecord::Base#attr_accessible</tt>).
0
# has_one :credit_card, :dependent => :destroy # destroys the associated credit card
0
@@ -863,6 +865,7 @@ module ActiveRecord
0
# to the +attr_readonly+ list in the associated classes (e.g. <tt>class Post; attr_readonly :comments_count; end</tt>).
0
# * <tt>:readonly</tt> - If true, the associated object is readonly through the association.
0
# * <tt>:validate</tt> - If false, don't validate the associated objects when saving the parent object. +false+ by default.
0
+ # * <tt>:accessible</tt> - Mass assignment is allowed for this assocation (similar to <tt>ActiveRecord::Base#attr_accessible</tt>).
0
# belongs_to :firm, :foreign_key => "client_of"
0
@@ -1034,6 +1037,7 @@ module ActiveRecord
0
# but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
0
# * <tt>:readonly</tt> - If true, all the associated objects are readonly through the association.
0
# * <tt>:validate</tt> - If false, don't validate the associated objects when saving the parent object. +true+ by default.
0
+ # * <tt>:accessible</tt> - Mass assignment is allowed for this assocation (similar to <tt>ActiveRecord::Base#attr_accessible</tt>).
0
# has_and_belongs_to_many :projects
0
@@ -1109,6 +1113,8 @@ module ActiveRecord
0
association = association_proxy_class.new(self, reflection)
0
+ new_value = reflection.klass.new(new_value) if reflection.options[:accessible] && new_value.is_a?(Hash)
0
if association_proxy_class == HasOneThroughAssociation
0
association.create_through_record(new_value)
0
self.send(reflection.name, new_value)
0
@@ -1357,7 +1363,7 @@ module ActiveRecord
0
:finder_sql, :counter_sql,
0
:before_add, :after_add, :before_remove, :after_remove,
0
+ :validate
, :accessible0
options[:extend] = create_extension_modules(association_id, extension, options[:extend])
0
@@ -1367,7 +1373,7 @@ module ActiveRecord
0
def create_has_one_reflection(association_id, options)
0
options.assert_valid_keys(
0
- :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly, :validate, :primary_key
0
+ :class_name, :foreign_key, :remote, :select, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :readonly, :validate, :primary_key
, :accessible0
create_reflection(:has_one, association_id, options, self)
0
@@ -1383,7 +1389,7 @@ module ActiveRecord
0
def create_belongs_to_reflection(association_id, options)
0
options.assert_valid_keys(
0
:class_name, :foreign_key, :foreign_type, :remote, :select, :conditions, :include, :dependent,
0
- :counter_cache, :extend, :polymorphic, :readonly, :validate
0
+ :counter_cache, :extend, :polymorphic, :readonly, :validate
, :accessible0
reflection = create_reflection(:belongs_to, association_id, options, self)
0
@@ -1403,7 +1409,7 @@ module ActiveRecord
0
:finder_sql, :delete_sql, :insert_sql,
0
:before_add, :after_add, :before_remove, :after_remove,
0
+ :validate
, :accessible0
options[:extend] = create_extension_modules(association_id, extension, options[:extend])
I am attempting to utilize mass-assign for my models, but can’t get the update_attributes to work correctly when I have association_collections as child models. My create methods work fine, since the hash passes in an Array value for these collections. I.E.:
emails => [ {…}, {…} ] )
But, when I try to edit/update my model, the field names in the form naturally have the :id of the email included in them, so that the resulting value passed to the mass-assign is not an Array, but a Hash of this form:
emails => {"5" => {…}, “6” => {…}}
Where the 5 and 6 are the :id values of the respective emails. This gets passed into the update_attributes, which eventually gets to:
AssociationCollection.replace(other_array)
which assumes “emails” to be an Array. Shouldn’t this replace method be “smarter” so that if a Hash is passed in, it will ascertain the :id values from it, and then reassign the model attributes accordingly? Furthermore, what would happen if there were a combination of updated models (emails) and perhaps one new email (that didn’t have an :id). Does the mass-assign functionality handle this situation?
Any help would be appreciated.
-Glenn