Class: Immigrant::KeyValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/immigrant/key_validator.rb

Instance Method Summary collapse

Instance Method Details

#valid?(key) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
# File 'lib/immigrant/key_validator.rb', line 3

def valid?(key)
  tables = connection.tables
  return false unless tables.include?(key.from_table)
  return false unless tables.include?(key.to_table)
  return false unless column_exists?(key.from_table, key.options[:column])
  return false unless column_exists?(key.to_table, key.options[:primary_key])
  return false unless key.options[:primary_key] == "id" || has_unique_index?(key.to_table, key.options[:primary_key])
  true
end