def association_valid?(reflection, record, index = nil)
        return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)

        context = validation_context unless [:create, :update].include?(validation_context)

        unless valid = record.valid?(context)
          if reflection.options[:autosave]
            indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors)

            record.errors.group_by_attribute.each { |attribute, errors|
              attribute = normalize_reflection_attribute(indexed_attribute, reflection, index, attribute)

              errors.each { |error|
                self.errors.import(
                  error,
                  attribute: attribute
                )
              }
            }
          else
            errors.add(reflection.name)
          end
        end
        valid
      end
def association_valid?(reflection, record, index = nil)
        return true if record.destroyed? || (reflection.options[:autosave] && record.marked_for_destruction?)

        context = validation_context unless [:create, :update].include?(validation_context)

        unless valid = record.valid?(context)
          if reflection.options[:autosave]
            indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors)

            record.errors.group_by_attribute.each { |attribute, errors|
              attribute = normalize_reflection_attribute(indexed_attribute, reflection, index, attribute)

              errors.each { |error|
                self.errors.import(
                  error,
                  attribute: attribute
                )
              }
            }
          else
            errors.add(reflection.name)
          end
        end
        valid
      end
Returns whether or not the association is valid and applies any errors to
 the parent, <tt>self</tt>, if it wasn't. Skips any <tt>:autosave</tt>
 enabled records if they're marked_for_destruction? or destroyed.