Sha256: 6a44c1e4a42b086900b8d8246127b3852ee46f5904ac38bdaf86b83a0dccc0db
Contents?: true
Size: 1.28 KB
Versions: 10
Compression:
Stored size: 1.28 KB
Contents
# frozen_string_literal: true module EacRailsUtils module Models module TablelessAssociations module ActiveRecordReflection extend ActiveSupport::Concern included do if ActiveRecord.version >= Gem::Version.new('4.1.2') class_attribute :_reflections self._reflections = ActiveSupport::HashWithIndifferentAccess.new else class_attribute :reflections self.reflections = {} end end module ClassMethods if ActiveRecord.version < Gem::Version.new('4.1') def create_reflection(macro, name, scope, options, active_record) case macro when :has_many, :belongs_to klass = ActiveRecord::Reflection::AssociationReflection reflection = klass.new(macro, name, scope, options, active_record) end self.reflections = reflections.merge(name => reflection) reflection end end def reflect_on_association(association) if ActiveRecord.version >= Gem::Version.new('4.1.2') _reflections[association.to_s] else reflections[association] end end end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems