Class: LolDba::BelongsTo

Inherits:
RelationInspector show all
Defined in:
lib/lol_dba/index_finding/belongs_to.rb

Instance Attribute Summary

Attributes inherited from RelationInspector

#model_class, #reflection_name, #reflection_options

Instance Method Summary collapse

Methods inherited from RelationInspector

#get_through_foreign_key, #initialize, #reflections

Constructor Details

This class inherits a constructor from LolDba::RelationInspector

Instance Method Details

#relation_columnsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/lol_dba/index_finding/belongs_to.rb', line 3

def relation_columns
  if reflection_options.options[:polymorphic]
    name = reflection_options.name
    poly_type = "#{name}_type"
    poly_id = "#{name}_id"
    [poly_type, poly_id].sort
  else
    foreign_key = non_polymorphic_fk

    # not a clue why rails 4.1+ creates this left_side_id thing
    foreign_key == 'left_side_id' ? nil : foreign_key.to_s
  end
end

#table_nameObject



17
18
19
# File 'lib/lol_dba/index_finding/belongs_to.rb', line 17

def table_name
  model_class.table_name
end