Sha256: a5412b7bd99c0dee34043286a49655320b68185ccb8e7ce1b8a075013197407e

Contents?: true

Size: 1.1 KB

Versions: 145

Compression:

Stored size: 1.1 KB

Contents

module CmAdmin
  module Models
    module Utils
      module Associations
        extend ActiveSupport::Concern

        def validation_for_association
          return unless field_type.to_s == "association"

          raise ArgumentError, 'Expected association_name and association_type to be present' if association_name.nil? || association_type.nil?

          if association_type.to_s == 'polymorphic'
            raise ArgumentError, "Expected field_name - #{field_name} - to be an array of hash. Eg, [{table_name_1: 'column_name_1'}, {table_name_2: 'column_name_2'}]" unless field_name.is_a?(Array)

            field_name.each do |element|
              raise ArgumentError, "Expected element #{element} to be a hash. Eg, [{table_name_1: 'column_name_1'}, {table_name_2: 'column_name_2'}]" unless element.is_a?(Hash)
            end
          elsif ['belongs_to', 'has_one'].include? association_type.to_s
            raise ArgumentError, "Expected field_name - #{field_name} to be a String or Symbol" unless field_name.is_a?(Symbol) || field_name.is_a?(String)
          end
        end
      end
    end
  end
end

Version data entries

145 entries across 145 versions & 1 rubygems

Version Path
cm-admin-4.4.8 lib/cm_admin/models/utils/associations.rb
cm-admin-4.4.6 lib/cm_admin/models/utils/associations.rb
cm-admin-4.4.1 lib/cm_admin/models/utils/associations.rb
cm-admin-4.4.0 lib/cm_admin/models/utils/associations.rb
cm-admin-4.3.0 lib/cm_admin/models/utils/associations.rb
cm-admin-4.2.1 lib/cm_admin/models/utils/associations.rb
cm-admin-4.2.0 lib/cm_admin/models/utils/associations.rb
cm-admin-4.1.2 lib/cm_admin/models/utils/associations.rb
cm-admin-4.1.1 lib/cm_admin/models/utils/associations.rb
cm-admin-4.1.0 lib/cm_admin/models/utils/associations.rb
cm-admin-4.0.0 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.16 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.15 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.14 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.13 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.12 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.11 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.10 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.9 lib/cm_admin/models/utils/associations.rb
cm-admin-3.0.8 lib/cm_admin/models/utils/associations.rb