module Torque::PostgreSQL::Reflection::AssociationReflection

Public Class Methods

new(name, scope, options, active_record) click to toggle source
Calls superclass method
# File lib/torque/postgresql/reflection/association_reflection.rb, line 8
        def initialize(name, scope, options, active_record)
          super

          raise ArgumentError, <<-MSG.squish if options[:array] && options[:polymorphic]
            Associations can't be connected through an array at the same time they are
            polymorphic. Please choose one of the options.
          MSG
        end

Private Instance Methods

automatic_inverse_of() click to toggle source

returns either nil or the inverse association name that it finds.

Calls superclass method
# File lib/torque/postgresql/reflection/association_reflection.rb, line 28
def automatic_inverse_of
  return super unless connected_through_array?

  if can_find_inverse_of_automatically?(self)
    inverse_name = options[:as] || active_record.name.demodulize
    inverse_name = ActiveSupport::Inflector.underscore(inverse_name)
    inverse_name = ActiveSupport::Inflector.pluralize(inverse_name)
    inverse_name = inverse_name.to_sym

    begin
      reflection = klass._reflect_on_association(inverse_name)
    rescue NameError
      # Give up: we couldn't compute the klass type so we won't be able
      # to find any associations either.
      reflection = false
    end

    return inverse_name if valid_inverse_reflection?(reflection)
  end
end
derive_foreign_key() click to toggle source

Check if the foreign key should be pluralized

Calls superclass method
# File lib/torque/postgresql/reflection/association_reflection.rb, line 20
def derive_foreign_key
  result = super
  result = ActiveSupport::Inflector.pluralize(result) \
    if collection? && connected_through_array?
  result
end