Sha256: 8f258af0b4b65943101825c6354f43f7243e1a8ef97343ab5430e7f17a74621c

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Torque
  module PostgreSQL
    module Reflection
      class BelongsToManyReflection < ::ActiveRecord::Reflection::AssociationReflection
        def macro
          :belongs_to_many
        end

        def connected_through_array?
          true
        end

        def collection?
          true
        end

        def association_class
          Associations::BelongsToManyAssociation
        end

        def association_foreign_key
          @association_foreign_key ||= foreign_key
        end

        def active_record_primary_key
          @active_record_primary_key ||= options[:primary_key] || derive_primary_key
        end

        private

          def derive_foreign_key
            klass.primary_key
          end

          def derive_primary_key
            ActiveSupport::Inflector.pluralize(klass.name.foreign_key)
          end
      end

      ::ActiveRecord::Reflection::AssociationReflection::VALID_AUTOMATIC_INVERSE_MACROS.push(:belongs_to_many)
      ::ActiveRecord::Reflection.const_set(:BelongsToManyReflection, BelongsToManyReflection)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
torque-postgresql-1.0.1 lib/torque/postgresql/reflection/belongs_to_many_reflection.rb
torque-postgresql-1.0.0 lib/torque/postgresql/reflection/belongs_to_many_reflection.rb