You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: association_validator.rb
    path of file: ./repos/sequent/lib/sequent/core/helpers
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'active_model/validator'

module Sequent
  module Core
    module Helpers
      #
      # Validator for associations. 
    
        def validate(record)
          associations = options[:associations]
          associations = [associations] unless associations.instance_of?(Array)
          associations.each do |association|
            value = record.instance_variable_get("@#{association}")
            if value && incorrect_type?(value, record, association)
              record.errors.add(association, "is not of type #{describe_type(record.class.types[association])}")
            elsif value&.is_a?(Array)
              item_type = record.class.types.fetch(association).item_type
              record.errors.add(association, 'is invalid') unless validate_all(value, item_type).all?
            elsif value&.invalid?
              record.errors.add(association, 'is invalid')
            end
          end