method
collection_accessor_methods
collection_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class)
private
Hide source
# File activerecord/lib/active_record/associations.rb, line 751 def collection_accessor_methods(association_name, association_class_name, association_class_primary_key_name, options, association_proxy_class) define_method(association_name) do |*params| force_reload = params.first unless params.empty? association = instance_variable_get("@#{association_name}") unless association.respond_to?(:loaded?) association = association_proxy_class.new(self, association_name, association_class_name, association_class_primary_key_name, options) instance_variable_set("@#{association_name}", association) end association.reload if force_reload association end define_method("#{association_name}=") do |new_value| association = instance_variable_get("@#{association_name}") unless association.respond_to?(:loaded?) association = association_proxy_class.new(self, association_name, association_class_name, association_class_primary_key_name, options) instance_variable_set("@#{association_name}", association) end association.replace(new_value) association end define_method("#{Inflector.singularize(association_name)}_ids=") do |new_value| send("#{association_name}=", association_class_name.constantize.find(new_value)) end end