method

collection_accessor_methods

Importance_0
v2.1.0 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::ClassMethods
collection_accessor_methods(reflection, association_proxy_class, writer = true) 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 1143
        def collection_accessor_methods(reflection, association_proxy_class, writer = true)
          collection_reader_method(reflection, association_proxy_class)

          if writer
            define_method("#{reflection.name}=") do |new_value|
              # Loads proxy class instance (defined in collection_reader_method) if not already loaded
              association = send(reflection.name)
              association.replace(new_value)
              association
            end

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