class ConsistencyFail::Introspectors::HasOne
Public Instance Methods
instances(model)
click to toggle source
# File lib/consistency_fail/introspectors/has_one.rb, line 6 def instances(model) model.reflect_on_all_associations.select do |a| a.macro == :has_one && a.options[:as].to_s.length == 0 && a.options[:through].to_s.length == 0 end end
missing_indexes(model)
click to toggle source
# File lib/consistency_fail/introspectors/has_one.rb, line 27 def missing_indexes(model) desired = desired_indexes(model) existing_indexes = desired.inject([]) do |acc, d| acc += TableData.new.unique_indexes_by_table(d.model, d.model.connection, d.table_name) end desired.reject do |index| existing_indexes.include?(index) end end
Private Instance Methods
desired_indexes(model)
click to toggle source
TODO: handle has_one :through cases (multicolumn index on the join table?)
# File lib/consistency_fail/introspectors/has_one.rb, line 13 def desired_indexes(model) instances(model).map do |a| if a.respond_to?(:foreign_key) foreign_key = a.foreign_key else foreign_key = a.primary_key_name end ConsistencyFail::Index.new(a.klass, a.table_name.to_s, [foreign_key]) end.compact end