method

collection_accessor_methods

Importance_0
v1.1.6 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::ClassMethods
collection_accessor_methods(reflection, association_proxy_class) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations.rb, line 890
        def collection_accessor_methods(reflection, association_proxy_class)
          collection_reader_method(reflection, association_proxy_class)

          define_method("#{reflection.name}=") do |new_value|
            association = instance_variable_get("@#{reflection.name}")
            unless association.respond_to?(:loaded?)
              association = association_proxy_class.new(self, reflection)
              instance_variable_set("@#{reflection.name}", association)
            end
            association.replace(new_value)
            association
          end

          define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
            send("#{reflection.name}=", reflection.class_name.constantize.find(new_value))
          end
        end
Register or log in to add new notes.