Class: ThinkingSphinx::ActiveRecord::AssociationProxy::AttributeFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb

Instance Method Summary collapse

Constructor Details

#initialize(association) ⇒ AttributeFinder

Returns a new instance of AttributeFinder



2
3
4
# File 'lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb', line 2

def initialize(association)
  @association = association
end

Instance Method Details

#attributeObject



6
7
8
9
10
11
12
13
14
# File 'lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb', line 6

def attribute
  attributes.detect { |attribute|
    # Don't bother with attributes built from multiple columns
    next if attribute.columns.many?

    attribute.columns.first.__name == foreign_key.to_sym ||
    attribute.name == foreign_key.to_s
  } or raise "Missing Attribute for Foreign Key #{foreign_key}"
end