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