module ActiveScaffold::ReverseAssociation::ThroughReflection

Public Class Methods

included(base) click to toggle source
# File lib/active_scaffold/extensions/reverse_associations.rb, line 83
def self.included(base)
  base.send :include, ActiveScaffold::ReverseAssociation::CommonMethods unless base < ActiveScaffold::ReverseAssociation::CommonMethods
end

Protected Instance Methods

reverse_matches(klass) click to toggle source
# File lib/active_scaffold/extensions/reverse_associations.rb, line 89
def reverse_matches(klass)
  reverse_matches = []

  # collect associations that point back to this model and use the same foreign_key
  klass.reflect_on_all_associations.each do |assoc|
    next if assoc == self
    # only iterate has_many :through associations
    next unless assoc.options[:through]
    next unless assoc.class_name == active_record.name
    next unless assoc.through_reflection.class_name == through_reflection.class_name

    reverse_matches << assoc
  end
  reverse_matches
end